Jump to content


Photo

Unsure how to pass id field in a link


  • Please log in to reply
2 replies to this topic

#1 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 24 June 2006 - 09:29 PM

Hello!

I wrote a script which enters a few variables into a database. I wanted to be able to click a link to add further details to the database. The plan was to have this on the page which echoes the variables just added to the db. (details which are not necessary, hence a different page to enter them on should the user want to add the further information) I am not certain how to create a link which will put the id into the link, so that on the resultant page I can add further info based on the ID. If someone could punt me in the right direction, I would be most appreciative (and my headache would go away)

Here's a snippet of some of the code I have. The link at the bottom doesn't add the ID, although I can echo it using the mysql_insert_id at the beginning:

<tr>
<td> ID:</td>
<td>'; echo mysql_insert_id(); echo'</td>
</tr>

<tr>
<td>First Name:</td>
<td>' .$fn. '</td>
</tr>

<tr>
<td>Middle Namee:</td>
<td>' .$mn. '</td>
</tr>

<tr>
<td class="header3">Last Name:</td>
<td>' .$ln. '</td>
</tr>

<tr>
<td class="header3">Birthday:</td>
<td>' .$bd. '</td>
</tr>

<tr>
<td>Add More Detail</td>
</tr>

<tr>
<td><a href="add_detail.php?id='.$id.'">Add Details</a></td>
</tr>

#2 ale_jrb

ale_jrb
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationLondon, UK

Posted 24 June 2006 - 10:25 PM

To get the ID, set it to a variable like so:
$id = mysql_insert_id()

Put the above variable as your link (/add_detail.php?id='.$id.').

Then on your add_detail.php page, you have to use the $_GET command.

For example:
if(isset($_GET['id'])){
$id = $_GET['id'];
$moreinfo = "true";
}

if($moreinfo = "true"){
Type code that you want to happen if the link is clicked here...
}
else
{
Type code you want to happen if the page is accessed by typing "www.yoururl.com/add_detail.php" in the browser by itself.
}

Does this help you? Your question is quite unclear.

#3 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 24 June 2006 - 10:57 PM

Thank you ale, that makes perfect sense. Pardon my unclear question, it makes perfect sense in my head, but when trying to express it in a question gets muddled .. Due to being a nooblet. I understand your reply, and I will implement!

Thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users