geroido Posted July 23, 2008 Share Posted July 23, 2008 Hi Can anyone help me with this. I'm pulling data from a database and displaying it on the webpage with a 'View menu details' submit button. There will be many hits from the database resulting in many 'view menu details' buttons. When the user clicks on any button I want to send the 'clientID, value retrieved for every record over in the form to menulist.php. Can you please tell me how to do this. The code is below: <form id="form1" method="post" action="menulist.php"> <TABLE cellspacing="10"> <TR><TD></TD><TD><font color="black" size=4>Name</TD><TD><font color="black" size=4>Address</TD></font></font></TR> <?php $query = "select clientID, busname, strAddr1, strAddr2, towncity, county FROM clientdetails where towncity = '".$_SESSION['town']."' order by busname asc"; $results = mysql_query($query, $link) or die("Error performing query"); if(mysql_num_rows($results) > 0){ while($row = mysql_fetch_object($results)){ echo ("<tr>"); echo ("<td>"); ?> <input type="submit" name="Submit" value="View menu details"> <? echo ("</td>"); echo ("<td>"); echo $row->busname; echo ("</td>"); echo ("<td>"); echo $row->strAddr1 . " " . $row->strAddr2 . " " . $row->towncity . " " . $row->county; echo ("</td>"); echo("</tr>"); } } else{ echo("<i>No values found</i>"); } ?> </TR> </TABLE></form> Link to comment https://forums.phpfreaks.com/topic/116161-how-to-send-data-in-a-form/ Share on other sites More sharing options...
JasonLewis Posted July 23, 2008 Share Posted July 23, 2008 Why not use $_GET instead of $_POST ? Link to comment https://forums.phpfreaks.com/topic/116161-how-to-send-data-in-a-form/#findComment-597463 Share on other sites More sharing options...
Entanio Posted July 23, 2008 Share Posted July 23, 2008 Instead of a form use a link? Like Project fear said, so you would have echo "<a href='menulist.php?busname=" .$row->busname. "' />"; Then on menulist.php: $busname = $_GET['busname']; mysql_query("SELECT ... WHERE busname=" .mysql_real_escape_string($busname). ""); Possible? Link to comment https://forums.phpfreaks.com/topic/116161-how-to-send-data-in-a-form/#findComment-597471 Share on other sites More sharing options...
geroido Posted July 23, 2008 Author Share Posted July 23, 2008 I've adjusted my code to the following to include a href option but it's not passing the value for $row->clientID over to the menulist.php page. Can you help <?php $query = "select clientID, busname, strAddr1, strAddr2, towncity, county FROM clientdetails where towncity = '".$_SESSION['town']."' order by busname asc"; $results = mysql_query($query, $link) or die("Error performing query"); if(mysql_num_rows($results) > 0){ while($row = mysql_fetch_object($results)){ $id = $row->clientID; ?><form id="form1" method="post" action="menulist.php?resid=$id"><? echo ("<tr>"); echo ("<td>"); ?><a href='menulist.php?resid=" .$row->clientID. "'>View menu</a><? echo ("</td>"); echo ("<td>"); echo $row->busname; echo ("</td>"); echo ("<td>"); echo $row->strAddr1 . $row->strAddr2 . " " . $row->towncity . " " . $row->county . " " . $row->clientID; echo ("</td>"); echo("</tr>"); echo("</form>"); } } else{ echo("<i>No values found</i>"); } ?> Link to comment https://forums.phpfreaks.com/topic/116161-how-to-send-data-in-a-form/#findComment-597511 Share on other sites More sharing options...
craygo Posted July 23, 2008 Share Posted July 23, 2008 since you came out of php for your link you have to go back in to get the value ?><a href='menulist.php?resid=<?php echo $row->clientID; ?>'>View menu</a><? Ray Link to comment https://forums.phpfreaks.com/topic/116161-how-to-send-data-in-a-form/#findComment-597517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.