Noonga Posted November 22, 2011 Share Posted November 22, 2011 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?? Quote Link to comment https://forums.phpfreaks.com/topic/251610-using-an-id-that-was-generated-via-auto-incrementation-using-null/ Share on other sites More sharing options...
trq Posted November 22, 2011 Share Posted November 22, 2011 Did you try looking in the manual? mysql_insert_id. Quote Link to comment https://forums.phpfreaks.com/topic/251610-using-an-id-that-was-generated-via-auto-incrementation-using-null/#findComment-1290385 Share on other sites More sharing options...
ManiacDan Posted November 22, 2011 Share Posted November 22, 2011 Also, you don't need to explicitly name the auto-increment column and pass it a null, simply leaving it out of the query entirely will still auto-fill it. Quote Link to comment https://forums.phpfreaks.com/topic/251610-using-an-id-that-was-generated-via-auto-incrementation-using-null/#findComment-1290396 Share on other sites More sharing options...
Noonga Posted November 22, 2011 Author Share Posted November 22, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/251610-using-an-id-that-was-generated-via-auto-incrementation-using-null/#findComment-1290404 Share on other sites More sharing options...
trq Posted November 22, 2011 Share Posted November 22, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251610-using-an-id-that-was-generated-via-auto-incrementation-using-null/#findComment-1290560 Share on other sites More sharing options...
ManiacDan Posted November 22, 2011 Share Posted November 22, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251610-using-an-id-that-was-generated-via-auto-incrementation-using-null/#findComment-1290571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.