Muhammad Nadeem
Muhammad Nadeem

Reputation: 366

Posting value through form hidden field in PHP

I have the following code:

<?php
$student_no = $_GET['student_no'];
echo '<form  name="student" action="PROCESS_FEE007.php" method="POST">';
echo '</br><table>';
echo '**<input name="student_no" type="hidden" value="$student_no"  />**';
echo '<td>Amount: </td><td>'.'<input name="amount" type="text" /></td></tr>'; 
echo '<tr> <td>Remarks: </td><td>'.'<input name="remarks" type="text"  /> </td>';
echo '<tr> <td>';
echo '<td>'.'<input type="submit" value="Save"/></td></tr>';
echo '</table>';
echo '</form>';
?>

On the next page PROCESS_FEE007.PHP the value is not received.

Upvotes: 2

Views: 20067

Answers (4)

Minras
Minras

Reputation: 4346

Variables are not parsed by interpreter inside single quotes. You should use double quotes or explicit string concatenation.

In your example the value of $_POST['student_no'] will be string '$student_no', not the value of the $student_no variable.

Besides if you're using method="POST" in your form, you can only get the inputs value through the $_POST array.

<?php
$student_no = $_POST['student_no'];
echo '<form  name="student" action="PROCESS_FEE007.php" method="POST">';
echo '</br><table>';
echo '**<input name="student_no" type="hidden" value="'.$student_no.'"  />**';
echo '<td>Amount: </td><td>'.'<input name="amount" type="text" /></td></tr>'; 
echo '<tr> <td>Remarks: </td><td>'.'<input name="remarks" type="text"  /> </td>';
echo '<tr> <td>';
echo '<td>'.'<input type="submit" value="Save"/></td></tr>';
echo '</table>';
echo '</form>';
?>

Upvotes: 4

Acn
Acn

Reputation: 1066

check the attribute "VALUE" of hidden input field. The value is not put in the field.

First make the input field a text box and after fixing the bug make it a hidden field.

may be useful. (I forgot cuz I am out of PHP long time).

Upvotes: 1

Dau
Dau

Reputation: 8858

parse student_no in form as

<?php
$student_no = $_GET['student_no'];

echo '<form  name="student" action="PROCESS_FEE007.php" method="POST">';
echo '</br><table>';
echo '**<input name="student_no" type="hidden" value="'.$student_no.'"  />**';
echo '<td>Amount: </td><td>'.'<input name="amount" type="text" /></td></tr>'; 
echo '<tr> <td>Remarks: </td><td>'.'<input name="remarks" type="text"  /> </td>';
echo '<tr> <td>';
echo '<td>'.'<input type="submit" name="submit_save" value="Save"/></td></tr>';
echo '</table>';
echo '</form>';
?>

and on the PROCESS_FEE007.php page use

<?php 
 if ($_POST['submit_save']){
    var_dump($_POST);die();
}

?>

Upvotes: 1

themhz
themhz

Reputation: 8424

try using $_REQUEST instead of get example $student_no = $_REQUEST['student_no'];

Upvotes: 0

Related Questions