"You have an error in your SQL syntax" but can't f

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
oskare100
Forum Commoner
Posts: 80
Joined: Sun Oct 29, 2006 5:47 am

"You have an error in your SQL syntax" but can't f

Post by oskare100 »

Hello,
I get this error message "You have an error in your SQL syntax" but I can't find anything wrong with my code.

Here is the problem:

Code: Select all

$sql45="INSERT INTO $user_tbl (username, password, ebay_username, ebay_status, ebay_email, paypal_status, paypal_email, num_purchases, business, first_name, last_name, address_street,	address_city, address_state, address_zip, address_country, address_status, created) VALUES ($payer_email, $password, $auction_buyer_id, $ebay_status, , $ebay_email, $payer_status, $payer_email, 1, $business, $first_name, $last_name, $address_street, $address_city, $address_state, $address_zip, $address_country, $address_status, NOW())";
$result45=mysql_query($sql45) or die( mysql_error() );
Could you please take a look at it and see if you can find anything?

Best Regards
Oskar R
jammr
Forum Newbie
Posts: 16
Joined: Mon Jan 22, 2007 12:10 am

Post by jammr »

Code: Select all

$sql45="INSERT INTO $user_tbl (username, password, ebay_username, ebay_status, ebay_email, paypal_status, paypal_email, num_purchases, business, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_status, created) VALUES ($payer_email, $password, $auction_buyer_id, $ebay_status, $ebay_email, $payer_status, $payer_email, 1, $business, $first_name, $last_name, $address_street, $address_city, $address_state, $address_zip, $address_country, $address_status, NOW())";
$result45=mysql_query($sql45) or die( mysql_error() );
Took out the extra comma you had, if that was it... use the code above.
oskare100
Forum Commoner
Posts: 80
Joined: Sun Oct 29, 2006 5:47 am

Post by oskare100 »

Hello,
Thanks, but it still doesn't work.. Gives me the same error. Can you think of anything else?

Best Regards
Oskar R
oskare100
Forum Commoner
Posts: 80
Joined: Sun Oct 29, 2006 5:47 am

Post by oskare100 »

Hello,
I added single quotes to it and that solved that problem, but now I get the same error with this code:

Code: Select all

// It is a file pack
$sql46="INSERT INTO $sales_tbl (user_id, pack_id, ebay_item_name,	ebay_item_id, ebay_txn_id, shipped_marked, paid_marked, payment_status, payment_date, payment_gross, payment_tax, payment_currency, payment_type, paypal_txn_id, paypal_memo, auction_closing_date, auction_multi_item, received) ) VALUES('".$row['user_id']."', '".$ident_row['pack_id']."', '$item_name', '$item_number', '$ebay_transaction_id', '$shipped_marked', '$paid_marked', '$payment_status', '$payment_date', '$mc_gross', '$tax', '$mc_currency', '$payment_type', '$txn_id', '$memo', '$auction_closing_date', '$auction_multi_item')";
$result46=mysql_query($sql46) or die( mysql_error() );
And it didn't help to add single quotas to it.. Can you see anything else with it?

Thanks in advance,
Oskar R
jammr
Forum Newbie
Posts: 16
Joined: Mon Jan 22, 2007 12:10 am

Post by jammr »

I can't find anything wrong with the query itself, I'm guessing it has something to do with one of the variables...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

There's no need to squeeze everything into one line. It only makes debgging harder. The mysql server reports the line in which the error occured but if there's only line it will always be #1 - useless. Format the sql query.

Code: Select all

$sql46="INSERT INTO
		$sales_tbl (
			user_id, pack_id,ebay_item_name,ebay_item_id, ebay_txn_id,
			...
	VALUES (
		'".$row['user_id']."', '".$ident_row['pack_id']."', '$item_name', '$item_number', '$ebay_transaction_id',
		...
	";
oskare100
Forum Commoner
Posts: 80
Joined: Sun Oct 29, 2006 5:47 am

Post by oskare100 »

Problem solved.
Post Reply