Jump to content

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>
Link to comment
https://forums.phpfreaks.com/topic/12825-unsure-how-to-pass-id-field-in-a-link/
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.
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.