rondog Posted November 13, 2009 Share Posted November 13, 2009 I am trying to get the ID of a row I just inserted obviously. my id field is auto_increment. This is my code: $userQuery = mysql_query("INSERT INTO $tableName (username,email,firstname,lastname,company,date_added,confirmation_key) VALUES ('$username','$email','$firstName','$lastName','$company','$date_added','$confKey')") or die(mysql_error()); $insertID = mysql_insert_id($userQuery); $expiry_period = $results['expiry_period']; $expirationDate = strtotime("+".$expiry_period." minutes"); $tokenQuery = mysql_query("UPDATE $tokenTable SET client_id = '$insertID', active = 'yes', expiry_date = '$expirationDate' WHERE token = '$password'") or die(mysql_error()); Basically I am inserting the user and I need to take the ID of that new user and put it in another table but I am getting the error: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource Quote Link to comment https://forums.phpfreaks.com/topic/181337-solved-help-with-mysql_insert_id/ Share on other sites More sharing options...
rondog Posted November 13, 2009 Author Share Posted November 13, 2009 doh! figured it out...just use mysql_insert_id()...nothing in the parens Quote Link to comment https://forums.phpfreaks.com/topic/181337-solved-help-with-mysql_insert_id/#findComment-956620 Share on other sites More sharing options...
Alex Posted November 13, 2009 Share Posted November 13, 2009 Check the manual, mysql_insert_id() doesn't take a mysql query resource as a parameter. It takes the mysql connection link, which is only an optional parameter. Just try: $insertID = mysql_insert_id(); Quote Link to comment https://forums.phpfreaks.com/topic/181337-solved-help-with-mysql_insert_id/#findComment-956621 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.