Jump to content

[SOLVED] Can anyone see what I'm doing wrong?


poleposters

Recommended Posts

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 ('','[email protected]', 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

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')";

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.

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?

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.