Xtremer360 Posted October 1, 2010 Share Posted October 1, 2010 How can you debug to find out why it's not getting the mysql_insert_id number? I have it echoed all the queries and all with all the correct values from my form but the only problem is that its not getting the insert id number of the id. $query1 = "INSERT INTO `efed_bio` (charactername,username,posername,style_id,gender,status_id,division_id,alignment_id,sortorder) VALUES ('".$charactername."','".$username."','".$posername."','".$style."','".$gender."','".$status."','".$division."','".$alignment."','".$sort."')"; mysql_query($query1); $query1_id = mysql_insert_id(); echo $query1; echo $query1_id; $query2 = "INSERT INTO `efed_bio_allies` (bio_id) VALUES (".$query1_id.")"; mysql_query($query2); echo $query2; $query3 = "INSERT INTO `efed_bio_rivals` (bio_id) VALUES (".$query1_id.")"; mysql_query($query3); echo $query3; $query5 = "INSERT INTO `efed_bio_singles` (bio_id) VALUES (".$query1_id.")"; mysql_query($query5); echo $query5; Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted October 1, 2010 Share Posted October 1, 2010 Is the field set to auto_increment? Quote Link to comment Share on other sites More sharing options...
chintansshah Posted October 1, 2010 Share Posted October 1, 2010 Please find detail function inputs and outputs on php.net website http://in3.php.net/manual/en/function.mysql-insert-id.php Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 1, 2010 Share Posted October 1, 2010 perhaps... $query1 = "INSERT INTO efed_bio (charactername, username, posername, style_id, gender, status_id, division_id, alignment_id, sortorder) VALUES ('$charactername', '$username', '$posername', '$style', '$gender', '$status', '$division', '$alignment', '$sort')";$result1 = mysql_query($query1);$query1_id = mysql_insert_id(); echo $query1;echo $query1_id;$query2 = "INSERT INTO efed_bio_allies (bio_id) VALUES ('$query1_id')";$result2 = mysql_query($query2); echo $query2;$query3 = "INSERT INTO efed_bio_rivals (bio_id) VALUES ('$query1_id')";$result3 = mysql_query($query3); echo $query3;$query5 = "INSERT INTO efed_bio_singles (bio_id) VALUES ('$query1_id')";$result5 = mysql_query($query5); echo $query5; Quote Link to comment Share on other sites More sharing options...
Pawn Posted October 1, 2010 Share Posted October 1, 2010 How can you debug code that doesn't bother to check if what its doing is working? Echo'ing SQL isn't going to help. As chintansshah suggested, read the manual entry and check for unexpected return values. Return Values The ID generated for an AUTO_INCREMENT column by the previous query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established. $sql = "INSERT INTO..."; // snipif(!$query = mysql_query($sql)) { // mysql_query returned FALSE echo "Error: a query failed on line ".__LINE__.". ".mysql_error(); exit;}if(!$insert_id = mysql_insert_id()) { // mysql_insert_id returned FALSE echo "Error: no MySQL connection was established."; exit;} elseif($insert_id == 0) { // mysql_insert_id returned 0 echo "Error: the previous query did not generate an AUTO_INCREMENT value."; exit;} Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 1, 2010 Author Share Posted October 1, 2010 Is the field set to auto_increment? Yes Quote Link to comment Share on other sites More sharing options...
schilly Posted October 1, 2010 Share Posted October 1, 2010 What does echo $query1_id; output? Does the row get inserted into efed_bio? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 1, 2010 Author Share Posted October 1, 2010 yes Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 8, 2010 Author Share Posted October 8, 2010 I finally figured out stupidly that there was a field I was declaring in my query that I didn't have in my db table. Quote Link to comment 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.