1

On my website i got a form looks like this on index.html:

<form id="demo" action='submit.php' method='post' enctype='text/plain'>
link: <input type='text' name='web'></br>
<input type='submit' value='submit'>
</form>

And then in the submit.php i got:

<?php
$fp=fopen('sub.txt','a'); 
fwrite($fp,addslashes($web)); 
fclose($fp); 
header('location: thanks.html'); 
exit();
?>

But when i press submit the result in sub.php is beeing

/n

But it should be

example.com/n

What is wrong in the php code.

I want the link submited in the form printed in the file sub.txt and then the person be redirected to a thank you page.

4

1 回答 1

2

您缺少value属性以及需要$_POST获取 sub.php 中的值

<form id="demo" action='submit.php' method='post' enctype='text/plain'>
link: <input type='text' name='web' value="" /></br>
<input type='submit' value='submit' />
</form>

<?php
$fp=fopen('sub.txt','a'); 
fwrite($fp,addslashes($_POST['web']). "\r\n"); 
fclose($fp); 
header('location: thanks.html'); 
exit();
?>
于 2013-05-25T15:47:04.627 回答