...

View Full Version : Updating Problem



Ironbar
03-22-2004, 07:28 AM
I am having trouble getting a code to update my db. I am sure that the variable is being passed and I *think* I have the code correct, however I get a "Error in SQL syntax."

Here is the code:

<?

header("Refresh: 3; URL=item.php?StockNum=$ud_StockNum");
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password) or die ('I cannot connect to the database because: ' . mysql_error());;
@mysql_select_db("forklift_used") or die( "Unable to select database");

$query="UPDATE used SET Make='$ud_Make', Model='$ud_Model', Price='$ud_Price', Terms='$ud_Terms', SerialNum='$ud_SerialNum' WHERE StockNum='$ud_StockNum'";
mysql_query($query) or die(MySQL_Error()); ;

$query="UPDATE used SET Desc='$ud_Desc' WHERE StockNum='$ud_StockNum'";
mysql_query($query) or die(MySQL_Error()); ;

echo "Stock Number "; echo $ud_StockNum; echo " Updated. Please Wait...";


mysql_close();


?>

The first update statement works fine but the second results in the error. The only difference that I can see between the two is that the "Desc" variable is a text type field that includes HTML.

Any help you can give!

Thanks!

Nightfire
03-22-2004, 12:21 PM
What's the error?

Az`
03-22-2004, 01:33 PM
Put something like echo '1'; before each query: then you can tell which one it's halting on.

Ironbar
03-22-2004, 04:18 PM
Here is the error I recieve. I know it is from the second update statement.

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Desc='3,000# Lift Capacity


Could it be because the Desc variable is of text type and is defined as:

<B>3,000# Lift Capacity</B><BR>
<BR>
<BR>
<BR>
Serial Number W13456<BR>
<BR>
183" Lift<BR>
<BR>
3 Wheel Triple Mast<BR>
<BR>
172" TSU<BR>
<BR>
<BR>
<BR>
<I>Price Includes Charger</I><BR>
<BR>


Thanks

Az`
03-22-2004, 04:39 PM
Before using the strings straight into the database, try putting addslashes($string).

Ironbar
03-22-2004, 06:46 PM
I added the addslashes($string) but that didn't seem to help. Just to check, I changed the $desc variable to equal "test" so there would not be any errors.

I still get the following error:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Desc='test' WHERE StockNum=64000' at line 1

It is like I do have a syntax error but the statement is the same as the one above it. I don't get it. <sigh>

Ironbar
03-23-2004, 01:44 AM
That's funny. (not really)

Apparently you can have a variable named $desc and you can use it in a form but you can not do an update with desc or it errors. I guess it's back to PHP 101 for me.

Sigh, I renamed the variable $longdesc and all is good.

Thanks for your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum