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 ('','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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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