Forum Moderators: coopster

Message Too Old, No Replies

INSERT error

It's breaking my string...

         

inveni0

6:10 pm on Feb 16, 2007 (gmt 0)

10+ Year Member



Here's the code:

$XY = $X.".".$Y;

//Construct SQL String
$insertSQL = sprintf("INSERT INTO Realms (Name, X, Y, ID, XY) VALUES (%s, %s, %s, %s, %s)",
$Name,
$X,
$Y,
$ID,
$XY);

And the error is:

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 ' 0.0)' at line 1

So, it's basically ending my string at the $XY variable. What gives?

inveni0

6:14 pm on Feb 16, 2007 (gmt 0)

10+ Year Member



I've also tried:

$insertSQL = "INSERT INTO Realms (Name, X, Y, ID, XY) VALUES ($Name, $X, $Y, $ID, $XY)";

mcavic

6:17 pm on Feb 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need single quotes around each variable:

$insertSQL = "INSERT INTO Realms (Name, X, Y, ID, XY) VALUES ('$Name', '$X', '$Y', '$ID', '$XY')";

LifeinAsia

6:18 pm on Feb 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What is the datatype for XY? If it's a CHAR or VARCHAR, you'll need single quotes around the value.

[edited by: LifeinAsia at 6:19 pm (utc) on Feb. 16, 2007]

inveni0

6:30 pm on Feb 16, 2007 (gmt 0)

10+ Year Member



Yeah, I just got it. Thanks though!