Page 1 of 1

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

Posted: Mon Jan 22, 2007 2:21 am
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

Posted: Mon Jan 22, 2007 2:27 am
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.

Posted: Mon Jan 22, 2007 2:38 am
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

Posted: Mon Jan 22, 2007 2:49 am
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

Posted: Mon Jan 22, 2007 2:55 am
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...

Posted: Mon Jan 22, 2007 2:59 am
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',
		...
	";

Posted: Mon Jan 22, 2007 3:53 am
by oskare100
Problem solved.