Jump to content

Help Passing Variable into next page


LCrane86

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.