0

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
Leena Patel
  • 2,423
  • 1
  • 14
  • 28
  • Please [don't use `mysql_*`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1); the `mysql_*` functions are outdated, [deprecated](http://us3.php.net/manual/en/intro.mysql.php), and insecure. Use [`MySQLi`](http://us3.php.net/manual/en/book.mysqli.php) or [`PDO`](http://us3.php.net/manual/en/intro.pdo.php) instead. Also, you are wide open to [**SQL injection**](https://www.owasp.org/index.php/SQL_Injection). – elixenide Sep 30 '15 at 04:52
  • @chintanmathukiya Don't edit out errors in the code. That's not a valid edit, and the errors you tried to fix are very likely the source of OP's problems here. – elixenide Sep 30 '15 at 05:22
  • your code is fine... I have checked and create same code on my machine and value of textarea is there. use print_r($_POST); die; on php file – Sunny S.M Sep 30 '15 at 05:40
  • Where you are facing problem to save Data OR anything else... – Sunny S.M Sep 30 '15 at 05:42

4 Answers4

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.

Suyog
  • 2,472
  • 1
  • 14
  • 27
  • made tag changes and tried all.. but still textarea value is not displayed ... radio button value is displayed but textarea shows empty value – Leena Patel Sep 30 '15 at 05:16
0

You are closing php tag too early.

MACMAN
  • 1,883
  • 1
  • 21
  • 35
0

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.

Community
  • 1
  • 1
elixenide
  • 44,308
  • 16
  • 74
  • 100
  • ya i have made changes in php closing still the problem is as it was.. It doesnt post textarea value. – Leena Patel Sep 30 '15 at 04:59
  • I m currently working on localhost so i m using mysql for demo only – Leena Patel Sep 30 '15 at 04:59
  • @leenapatel Are you sure? It should work now that you have fixed the PHP tag problem. Also, developing using a deprecated library just because you're on localhost is really bad practice. – elixenide Sep 30 '15 at 05:02
  • @leenapatel please note that in your code as posted now, you don't have an opening ` – elixenide Sep 30 '15 at 05:04
  • @leenapatel *What* tag changes have you made? Your PHP code as posted in your question either (1) is wrong for the reasons I have already pointed out or (2) is incomplete because it has no opening tag. It's impossible to help without seeing the actual code that is giving you problems. – elixenide Sep 30 '15 at 05:18
  • @leenapatel First, that's not the real problem. You still don't have an opening ` – elixenide Sep 30 '15 at 05:28
0

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"]

lakshman
  • 656
  • 4
  • 18