Jump to content

[SOLVED] Submit Button - submit record & parse recordID to next page


yandoo

Recommended Posts

Hi there,

 

Is is possible to get a submit button to not only submit (insert) record but to then parse the record ID (of the record it has just inserted) to another page....so the details of the record (that was submitted) can be seen?????

 

I can do it with a hyperlink but how with a submit button???????

 

 

Thank you :)

Link to comment
Share on other sites

is there a form? if so put the value for of the variable in a

<input type="hidden" name="varname" value="<?php echo $variable; ?>">

 

make sure the form is to method="post" and then on the page it goes to do $_POST['varname']

Link to comment
Share on other sites

After you've submitted the data on the page, just run another query which will order by ID descending, and limit it to 1 result, like this:

 

<?php

$query = "SELECT * FROM myTable ORDER BY id DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$newEntry = mysql_fetch_object($result);

?>

 

That will return last entry to your table, make sure you put this after the insert though or you'll get the info of the one before the last entry!

Link to comment
Share on other sites

Thanks for the reply thats gr8!

 

I know what you your saying with code u sugested

 

it im making a form that is completed over 2 different pages. I hoped it was possible that when submitting the record on the 1st page...it would then take you to the 2nd page (which it does) but then dynamically display the same record results just submitted.

 

Is it possible to parse the record ID from page to page with a submit button??

 

 

thank you

 

 

 

 

Link to comment
Share on other sites

On the second page, you could just echo out the information that was submitted from the previous form?  And then if you're wanting to then submit those details in addition to the ones completed in the second page of the form, do what kts said and store their values in hidden fields.

Link to comment
Share on other sites

You have x amount of fields on page1.php that the user fills out right?  Lets say, First Name + Surname.  Then they submit those (but not insert to the database) and go to page2.php, where there's some more fields for them to fill out (lets say Birthdate and Postcode).

 

You don't want to get them to input first name + surname again, nor do they need to be able to edit them.  So you store them in hidden fields, so that when they submit page2.php, you can access first name + surname as $_POST variables.  You could also echo out the first name + surname on page2.php if you wanted, just so they can see what they entered.

 

Once page2.php is submit, you insert all the fields to your table :)

 

Unless I've totally misunderstood your original question of course :D

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.