Hi,

I have built a form that send the info to the database. However I need the form to put the id of the entry into the url so I can get it on the next page. so that I can add more info.
The form goes over 2 pages. the first page is to add the info and the second is to add images.
So i need the id to pass through the url otherwise I cant put them both together in the same database.

If anyone could point me in the right direction, or has done this and is able to explain it, that would be awesome.

Thanks.

QWaz

Hi,
Pls store the id value in a hidden variable.You can get this value while you submit the form.

pssubash is right. One way is to include a hidden field and use that to get the value:

<input type="hidden" id="id_number" name="id_number" value="<?php echo $id; ?>" />

You would retrieve this with $_POST["id_number"] , same as the other fields in your form.

Alternatively, however, if you really want to use GET for the id instead of POST, you can include the id in the action attribute of the form tag:

<form method="post" action="mysite.com/process.php?id=<?php echo $id; ?>">

You would retrieve this with $_GET["id"] .

Sorry, I think I may have asked the wrong question.

Let me explain again what I am trying to do:

A form is adding information into a MySQL Database and creating a NEW id value for that entry.

I then want get that NEW (unknown) "id" from that entry and get it into my url or post it to the next page.

So when the form is initally sent, I have no idea what the id will be. so I can't use a $id to send it as I don't know what the id will be.

I hope this makes more sense.

Do you know how to do that?

Cheers,

QWaz

Ohhhh ok. Well, you can just use mysql_insert_id() right after you send your query to get the last ID created by AUTO_INCREMENT. Example:

$qry = "INSERT INTO tablename (col2, col3) VALUES ('value1', 'value2')";
if(mysql_query($qry))
   header("Location: http://www.mydomain.com/process.php?id=".mysql_insert_id());

For more info on this function, mysql_insert_id()

use mysql_insert_id to get the last inserted id

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.