LCrane86 Posted October 3, 2011 Share Posted October 3, 2011 Hello, I'm trying to build a small project; and as part of it - I want users to search and when presented with relevant enteries in the SQL database - they should be able to click and retrieve a page dedicated to that entity. The problem I am having is in passing the 'id' of the search result onto the next (description) page. $SQL = "SELECT * FROM loads"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $clickid = $_GET['id']; print $db_field['id'] ."<a href=\"load_info.php?id=$id" . $id . "\" target=\"_self\" title=\"\">More Info</a>;"; print $db_field['depart:'] . "<BR>"; print $db_field['dest'] . "<BR>"; } I thought it was easy enough to pass the variable like above ("load_info.php?id=$id) and then grab it on the next page like so: $val = $_GET['clickid']; Unfortunately, it doesn't retrieve the info from the page before. If I insert a number in there, it does work correctly, but I really need the ID of the database entry to pass on so as to provide the user with further information. If anyone could help it would be appreciated. L. Quote Link to comment https://forums.phpfreaks.com/topic/248329-help-passing-variable-into-next-page/ Share on other sites More sharing options...
Muddy_Funster Posted October 3, 2011 Share Posted October 3, 2011 you seem to have your variables mixed up, your using $id when you should be using $clickid $SQL = "SELECT * FROM loads"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $clickid = $_GET['id']; print $db_field['id'] ."<a href=\"load_info.php?id=$clickid" . $clickid . "\" target=\"_self\" title=\"\">More Info</a>;"; print $db_field['depart:'] . "<BR>"; print $db_field['dest'] . "<BR>"; } then on the next page myou are trying to get clickid when it should be id $var = $_GET['id']; I am surprised that you didn't get undeclared variable warnings when you ran your code. Quote Link to comment https://forums.phpfreaks.com/topic/248329-help-passing-variable-into-next-page/#findComment-1275195 Share on other sites More sharing options...
LCrane86 Posted October 3, 2011 Author Share Posted October 3, 2011 Thanks for your help, but I'm still not successful in sorting this. The generic links page is here: http://www.space.greensenvironmental.com/all_loads.php (just provides all records in the load table.) It should forward the $clickid into the next page(, but it doesn't. I've noticed the address bar at the bottom fails to show $clickid within " load_info.php?id=$clickid" - unless I do a injection attack in the address bar, it emerges with the id number. All Loads $SQL = "SELECT * FROM loads"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $clickid = $_GET['id']; print $db_field['id'] ."<a href=\"load_info.php?id=$clickid" . $id . "\" target=\"_self\" title=\"\">More Info</a>;"; print $db_field['depart:'] . "<BR>"; print $db_field['dest'] . "<BR>"; print $db_field['depart_date'] . "<BR>"; print $db_field['dest_date'] . "<BR>"; } mysql_close($db_handle); And the second page doesn't seem to 'grab' the $clickid var $var = $_GET['id']; echo $var; Something so small is really stopping my progress! L. Quote Link to comment https://forums.phpfreaks.com/topic/248329-help-passing-variable-into-next-page/#findComment-1275219 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 Your click id isnt in the GET array until you send it across.. Therefore on the all_loads.php $clickid should be set from the mysql result. while ($db_field = mysql_fetch_assoc($result)) { $clickid = $db_field['id']; print $db_field['id'] ."<a href=\"load_info.php?id=$clickid\" title=\"\">More Info</a>;"; print $db_field['depart:'] . "<BR>"; print $db_field['dest'] . "<BR>"; print $db_field['depart_date'] . "<BR>"; print $db_field['dest_date'] . "<BR>"; } Quote Link to comment https://forums.phpfreaks.com/topic/248329-help-passing-variable-into-next-page/#findComment-1275228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.