I need some help with my PHP Code, using MySQL...?

  • Thread starter Thread starter Josh
  • Start date Start date
J

Josh

Guest
Hello,

I am receiving a syntax error in my SQL Code, but it looks 100% right to me.

Code:
------------------(not in code)-------------------
$query = "INSERT INTO creations (name, desc) VALUES('$_POST[product_name]', '$_POST[product_desc]')";

if(!mysql_query($query, $link))
{
print mysql_errno().': '.mysql_error()."<br />\n";
}
------------------(not in code)-------------------

The error I am receiving is a generic SQL Syntax error.

Error:

1064: 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) VALUES('test name', 'test desc')' at line 1

Thank your for your time
 
$query = "INSERT INTO creations (name, desc) VALUES('$_POST[product_name]', '$_POST[product_desc]')";

is wrong

$query = "INSERT INTO creations (name,desc) <---- space after '
VALUES('$_POST[product_name]', '$_POST[product_desc]')";

which really shouldn't matter

or you are doing a big NO NO...allowing unchecked info

i would

$query = "INSERT INTO creations (name, desc) VALUES('" . addslashes($_POST['product_name']) . "', '" . addslashes($_POST['product_desc'] . "')";
 
Back
Top