Jump to content

Archived

This topic is now archived and is closed to further replies.

BadGoat

Unsure how to pass id field in a link

Recommended Posts

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>

Share this post


Link to post
Share on other sites
To get the ID, set it to a variable like so:
[code]$id = mysql_insert_id()[/code]

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:
[code]
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.
}
[/code]

Does this help you? Your question is quite unclear.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

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.