poleposters Posted April 14, 2008 Share Posted April 14, 2008 This is a snippet from my registration page. The script has three insert queries. I check the mysql_affected_rows after each query and increase a counter. If the counter after the three queries =3, the queries were successful and the script proceeds. However I get this error when I submit the form An error occurred in script 'C:\xampp\htdocs\registrationnew.php' on line 159: Query: INSERT INTO users (business_id, email, pass,business, business_type, first_name, last_name, active,paid_listing, registration_date) VALUES ('','pole@gmail.com', SHA('roscoe'),'dsdsdsds', '1','matt', 'andrian', '977be5ec4ba642af1e008fab149bb235','0', NOW() ) MySQL Error: Column count doesn't match value count at row 1 $count=0; $query = "INSERT INTO users (business_id, email, pass,business, business_type, first_name, last_name, active,paid_listing, registration_date) VALUES ('','$e', SHA('$p'),'$bn', '$cat','$fn', '$ln', '$a','0', NOW() )"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if(mysql_affected_rows()==1){$count ++;} $bid=mysql_insert_id(); $query2 = "INSERT INTO address (address_id,business_id,unit_number,street_number, address, postcode) VALUES ('','$bid','$un','$sn' '$ad','$pc')"; $result2 = mysql_query ($query2) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if(mysql_affected_rows()==1){$count ++;} $query3 = "INSERT INTO phone (contact_id,business_id,phone_one) VALUES ('','$bid','$ph')"; $result3 = mysql_query ($query2) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if(mysql_affected_rows()==1){$count ++;} if($count=3){ echo "woohooo"; I've looked up the error on google and PHP freaks and have looked at the code carefully but still can't see what I'm doing wrong. Perhaps someone with fresh eyes can help. Thank you Quote Link to comment Share on other sites More sharing options...
friedemann_bach Posted April 14, 2008 Share Posted April 14, 2008 I suppose that your field "business_id" is set to auto_increment (you are using mysql_insert_id()) and therefore it should be excluded from your INSERT statement. Omitting it could help. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 14, 2008 Share Posted April 14, 2008 The error actually originates from your second query - the reason why it appears to be from the first is that you have $query in all your error messages, but the query changes from $query to $query2 and then $query3. Hence, if there is an error on $query2, the error message contains $query. You were missing a comma in your second query. Try: $query2 = "INSERT INTO address (address_id,business_id,unit_number,street_number, address, postcode) VALUES ('','$bid','$un','$sn','$ad','$pc')"; Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 14, 2008 Share Posted April 14, 2008 I suppose that your field "business_id" is set to auto_increment (you are using mysql_insert_id()) and therefore it should be excluded from your INSERT statement. Omitting it could help. Not true - if you dont specify a value in an insert query, the default will be used. In the case of auto-increment field, that will be next number. Quote Link to comment Share on other sites More sharing options...
poleposters Posted April 14, 2008 Author Share Posted April 14, 2008 Thank you! The queries ran without error. The success condition was executed. Except something strange has happened in my database. The user query inserted correctly. The address query inserted twice and the phone query din't insert at all! Am i doing something else wrong? Quote Link to comment Share on other sites More sharing options...
friedemann_bach Posted April 14, 2008 Share Posted April 14, 2008 @GingerRobot: I see - thank you, that's good to know. Quote Link to comment Share on other sites More sharing options...
poleposters Posted April 14, 2008 Author Share Posted April 14, 2008 Eureka! I found what I was doing wrong. Very stupid. $query3 = "INSERT INTO phone (contact_id,business_id,phone_one) VALUES ('','$bid','$ph')"; $result3 = mysql_query ($query2) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); I ran $query2 twice. I've been looking at this script all day! Its true. When you can't figure it out. STEP AWAY FROM THE COMPUTER Thank you all for your help. 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.