phplearner2008 Posted August 25, 2008 Share Posted August 25, 2008 Hi, I have a php code which outputs data from database based on a search condition which is as follows: <?php echo '<form name="form1" method="post" action="mypage.php">'; while($row = mysql_fetch_array($result)) { echo $row['ID']; echo $row['NAME']; echo $row['AGE']; echo $row['HEIGHT']; echo $row['EDUCATION']; echo '<input type="submit" name="Submit" value = "submit">'; } echo '</form>'; mysql_close($con); ?> I want to send the ID to be sent to mypage.php whenever Submit button is clicked. Should I use hidden field? If so, how do I send the ID of each person in the value attribute of hidden field? I want $row['ID'] value to be send to the next page. Can anyone please help me? Link to comment https://forums.phpfreaks.com/topic/121211-solved-how-to-send-dynamic-value-using-hidden-fields/ Share on other sites More sharing options...
Fadion Posted August 25, 2008 Share Posted August 25, 2008 You can use different methods for this. One should be sending the id via get in the form action and the other using hidden inputs: Via GET if you have only one variable to send <?php //query and stuff $values = mysql_fetch_array($results); echo '<form name="form1" id="form1" method="post" action="mypage.php?id=' . $values['id'] . '">'; //other form elements ?> And you can retrieve that id using $_GET['id'] and the other elements with a regular $_POST. In the other hand, if you want to pass multiple ids, use a hidden input as you stated: <?php while($row = mysql_fetch_array($result)){ echo '<input type="hidden" name="id[]" value = "' . $row['id'] . '">'; } ?> It will generate as many hidden inputs you want, with the name "id[]". The square paranthesis makes the hidden inputs an array, so you can easily call them in mypage.php by using: <?php $ids = $_POST['id']; print_r($ids); //will print the ids as an array, which you can easily loop using foreach() ?> Link to comment https://forums.phpfreaks.com/topic/121211-solved-how-to-send-dynamic-value-using-hidden-fields/#findComment-624831 Share on other sites More sharing options...
waynew Posted August 25, 2008 Share Posted August 25, 2008 Hidden field inputs are bad news. Link to comment https://forums.phpfreaks.com/topic/121211-solved-how-to-send-dynamic-value-using-hidden-fields/#findComment-624868 Share on other sites More sharing options...
Fadion Posted August 25, 2008 Share Posted August 25, 2008 Hidden field inputs are bad news. Hmm. Can you expand your idea? Link to comment https://forums.phpfreaks.com/topic/121211-solved-how-to-send-dynamic-value-using-hidden-fields/#findComment-624871 Share on other sites More sharing options...
phplearner2008 Posted August 26, 2008 Author Share Posted August 26, 2008 Thanks GuiltyGear! It really works! Link to comment https://forums.phpfreaks.com/topic/121211-solved-how-to-send-dynamic-value-using-hidden-fields/#findComment-625673 Share on other sites More sharing options...
redarrow Posted August 26, 2008 Share Posted August 26, 2008 forget all that use sessions as it safer then seeing any info in the url........... unless your going to use mod_rewrite with $_GET[''].......... TIP.... never use hidden info in the form if it going to insert / update / search anythink to a database so that a NO........... Link to comment https://forums.phpfreaks.com/topic/121211-solved-how-to-send-dynamic-value-using-hidden-fields/#findComment-625675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.