0

I get the following error about my syntax

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 'replace='NOCOLOGY1' WHERE search='COMPANYNAME'' at line 1

$comp = "UPDATE msp_rereplacer SET replace='".addslashes($_POST[companyname])."' WHERE search='COMPANYNAME' ";

Can anyone pinpoint what I am missing?

3
  • addslashes() is not sufficient to prevent SQL Injection. Use a prepared/parameterised query. Commented Dec 10, 2012 at 12:15
  • use mysql_real_escape_string() Commented Dec 10, 2012 at 12:16
  • It is a one time use script, so security issues will not matter as I delete after one use! Commented Dec 10, 2012 at 12:17

2 Answers 2

2

replace is Reserved Words try backticksreplacebackticks

and

 .addslashes($_POST[companyname]).

should be

.addslashes($_POST['companyname']).

$comp = "UPDATE msp_rereplacer SET `replace`='".addslashes($_POST['companyname'])."' WHERE search='COMPANYNAME' ";

rather

$comp = "UPDATE msp_rereplacer SET `replace`='".mysql_real_escape_string($_POST['companyname'])."' WHERE search='COMPANYNAME' ";

Note

Use of this extension(mysql_*) is discouraged. Instead, the MySQLi or PDO

Good Read

addslashes() Versus mysql_real_escape_string()

Sign up to request clarification or add additional context in comments.

7 Comments

Tried switching this, did not help
@JustinBevan try above query
WHy dont use mysql_real_escape_string()
It is working now using backticks, but this isn't for an actual program, merely a one time use script. Thanks though!
@RohitKumarChoudhary yup .... addslashes is more worse ,,, rather i want to use prepared statements
|
0

replace is a MySQL reserved word.... quote it in backticks (`)

2 Comments

Tried $comp = "UPDATE msp_rereplacer SET 'replace'='".addslashes($_POST['companyname'])."' WHERE search='COMPANYNAME' "; with no luck
backticks (`), not single quotes (')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.