问题
I am facing problem in textarea content POST via PHP. I have a form that submits two values one in textarea and other radio button. while submitting the radio button value is posted but textarea value showed up empty.
why is this happening? Any suggestion would be appreciated..
My snippet of HTML Code
<form action="" method="post" id="register_form">
<h2><img class="small_image" src="images/rsz_heart.png">Describe
Yourself<img class="small_image" src="images/heart.png"></h2>
<table id="register_table">
<tr>
<td>Describe Yourself</td>
<td>
<textarea id="description" type="textarea" name="description" rows="5"
cols="40" class="textbox" form="register_form" required>type</textarea>
</td>
</tr>
<tr>
<td>Any disability</td>
<td>
<input type="radio" name="disability" value="none" selected="selected">None
<input type="radio" name="disability" value="physicaldisability">Physical
Disability
</td>
</tr>
<tr>
<td colspan=2>
<input type="submit" name="submit" value="Submit" class="button" >
</td>
</tr>
</table>
</form>
My PHP code is
if(isset($_REQUEST["submit"]))
{
$description = $_POST["description"];
$disability = $_POST["disability"];
$email = $_GET["email"];
$sql = "update Registration_members set Description_self='$description',
Disability='$disability' where Email='$email'";
$res = mysql_query($sql);
if($res)
{
?>
<script>
alert("You have registered successfully!!");
</script>
<?
echo $description." is description";
echo $disability." is disability";
}
}
?>
In output it writes
is description
none is disability
回答1:
Some edits to your code may solve your problem:
1) Always use <?php as starting PHP tag. You have used only <? at one place in your code. Change that.
2) Change isset($_REQUEST["submit"]) to isset($_POST["submit"])
3) Remove type="textarea" from your <textarea>
4) Be careful while opening and closing PHP tags. In your case, you have closed PHP tag just after if(isset($_REQUEST["submit"])) { which is wrong.
回答2:
You are closing php tag too early.
回答3:
Replace
<textarea id="description" type="textarea" name="description" rows="5"
cols="40" class="textbox" form="register_form" required>type</textarea>
by
<textarea id="description" name="description" rows="5"
cols="40" class="textbox" form="register_form" required></textarea>
type="textarea" is wrong, also use $_POST instead of $_REQUEST["submit"]
回答4:
You need an opening <?php tag or your code will not be interpreted as PHP.
In the original version of your question, on your third line, you had ?>. That closes the PHP block and means the next chunk of code is treated as plain HTML. So, it's never evaluated. Delete that line.
On that note, later in your code, you should use <?php, not <?, to start a new PHP code block.
Also, please don't use mysql_*; the mysql_* functions are outdated, deprecated, and insecure. Use MySQLi or PDO instead. On top of that, you are wide open to SQL injection.
来源:https://stackoverflow.com/questions/32858035/textarea-returns-empty-value-in-php-post