cancel
Showing results for 
Search instead for 
Did you mean: 

SQL syntax error although i dont know why

N/A

SQL syntax error although i dont know why

I get this error on screen "Failed during the insert of insert into Errors (Error_Solution) values ('the solution is n othing') where Error_Code = 6543562;"

when using the follwoing in my php page
mysql_db_query($DB_name, $sqlsol) or die("Failed during the insert of " . $sqlsol);

echo mysql_error($chan);

My sql statement looks like
$sqlsol="insert into Errors (Error_Solution) values ('" . $solution . "') where Error_Code = $_POST[id];";

The error_code field is an integer the error_solution is a mediumblob field. I have tried copying the insert statement that i output to the screen into my phpadmin page and get this

INSERT INTO Errors( Error_Solution )
VALUES (

'the solution is n othing'
)
WHERE Error_Code =6543562

MySQL said:


#1064 - You have an error in your SQL syntax near 'WHERE Error_Code =6543562' at line 3

i can't understand why its doing it as far as i know this is correct.

If anyone can offer me any advice that would be great. thanks
3 REPLIES
Marteknet
Grafter
Posts: 577
Registered: 13-10-2007

SQL syntax error although i dont know why

try this
$sqlsol="insert into 'Errors (Error_Solution)' values ('\" . $solution . \"') where Error_Code = $_POST[id];";

it excapes the "
not sure if this will work as i dont realy understand what the errors (error_solution) is doing in the database name field.

hope this helps.

Regards Peter
N/A

SQL syntax error although i dont know why

The (basic) format of INSERT commands is

INSERT INTO <table> [(fields, comma seperated)] VALUES (comma seperated list)


so

INERT INTO Errors (Error_Solution) VALUES ("This is an error") WHERE Error_Code = whatever


is invalid SQL.

If Error_Code whatever already exists, you want an UPDATE statement

UPDATE <table> SET field = value WHERE Error_Code = Whatever


(missing out the WHERE clause will set field=value globally in the table.

If it doesn't and you want to set Error_Code whatever you would do

INSERT INTO Errors (Error_Code, Error_Solution) VALUES (code, solution)


WHERE code and solution are the values or PHP variables.
salis
Dabbler
Posts: 19
Registered: 29-08-2007

Re: SQL syntax error although i dont know why

You cant do an INSERT statement with a WHERE clause in it. You will need to use UPDATE