Jump to content

How do I retreive the data I just updated to a mysql database?


Phrank

Recommended Posts

I have the user fill out a request form. When they hit the submit button I send them to a web page that adds the data to a mysql database - via the post method - then I want to send the owner an email that says so and so just sent you a contact request.

 

Problem is the fields in the web page are blank after I do the update - like ContactsFirstName etc.

 

How do I get this data back to use it over again on the same web page?

 

---------------------

$contactusnotes = addslashes($contactusnotes);

$TodaysDate=date("Y/m/d g:i:s a"); // H:m:s");

// echo "<br>todays date=". $TodaysDate;

$sql = mysql_query("INSERT INTO contactus (contactusfirstname,contactuslastname,contactustitle,contactuscompany,contactusemailaddress,contactusphonenumber,datecreated,contactusnotes,active)

VALUES ('$contactusfirstname','$contactuslastname','$contactustitle','$contactuscompany','$contactusemailaddress','$contactusphonenumber','$TodaysDate','$contactusnotes','Y')")

or die (mysql_error());

 

-------------------------------------

 

If the next thing I do is

echo "first name = " . $contactusfirstname;

the field is blank.

 

Is there a mysql statement that gets the data that you just added or updated?

 

Newby question - sorry.

 

TIA

Link to comment
Share on other sites

From what I had study so far, there is no sql statment for you to get what records you had just inserted justnow.

 

But you can do query based on the last records. Which means lets say your table had a Primary Key named 'ID' which is auto-increment.

 

So in your sql statement, "SELECT * FROM table ORDER BY ID DESC;". This will retrieve the latest data inserted.

 

This usage is limited and is not encourage because co-incidents will happened eg:

both users register at the same time, system will mistake one of them as the latest but instead it is not. Bugs happened.

 

Why you intended to do things separately? Why don't you put your email script and your INSERT Sql script in a same PHP file? Then you can use back the variables sent by your form. ???

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.