Jump to content

Using an id that was generated via auto incrementation using "null"


Noonga

Recommended Posts

I remember reading about a PHP operator that will allow me to use information from a previous MySQL entry or something.

 

What I am doing is executing this via PHP:

$query = "INSERT INTO orders (id, content, events) VALUES (null, '".mysql_real_escape_string($_SESSION['order']['cart']['content'])."', '".date(DATE_RFC822)."\nORDER WRITTEN TO DATABASE\n')";

 

Then later on in the script I need to use:

$query = "INSERT INTO orders (events) VALUES ('".date(DATE_RFC822)."\nEXECUTING PAYMENT\n') where id = XXXXX";

Where "XXXX" is the id. "id" is auto incrementing which is why I used "null" in the first query. So, I need to use the id number that was incremented.

 

What was that PHP operator again??

Link to comment
Share on other sites

thorpe,

 

No, I didn't look in the PHP manual because I didn't know what I was looking for and it would be silly for me possibly spending hours and hours looking for what I needed, when I could just ask someone for help that knows more about PHP than me.

 

Thanks for the link to the operator.

 

 

ManiacDan,

 

Ah, I didn't know. Thanks for the tip!

Link to comment
Share on other sites

No, I didn't look in the PHP manual because I didn't know what I was looking for and it would be silly for me possibly spending hours and hours looking for what I needed, when I could just ask someone for help that knows more about PHP than me.

 

Hours looking through the mysql section of the manual that lists maybe 60 functions? I don't think so. Learning to use the manual will save you hundreds of hours in the long run.

Link to comment
Share on other sites

While Thorpe is being pretty blunt, it's still true.  Reading the entire mysql section, including the comments, would take you half an hour.  It may seem daunting but there's really not that much text there.  The manual is laid out in such a way that you can even start from a list of all MySQL related functions and just read the list to find one that looks like what you want.  Even if you pick the wrong one, you still win by learning something new.

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.