PDA

View Full Version : MSSQL error: The name "XXX" is not permitted in this context...



mjkomidar
01-06-2010, 08:32 AM
Ok, so now I solved my last issue, but have hit the wall with this one... The following code produces this error:

MSSQL error: The name "XXX" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.


$sql = 'INSERT INTO tbl_jobs VALUES (';
$sql .= $_POST["company"];
$sql .= ',';
$sql .= $_POST["location"];
$sql .= ',';
$sql .= $_POST["title"];
$sql .= ',';
$sql .= $_POST["desc"];
$sql .= ',';
$sql .= $_POST["exper"];
$sql .= ',';
$sql .= $_POST["edu"];
$sql .= ',';
$sql .= $_POST["link"];
$sql .= ')';

In my troubleshooting, I verified that the variables are passing correctly, but it's treating it like a column name (according to the error). According to what I have seen, the syntax looks ok, but again, I am confused. I have googled this, but no luck so far.

ahmad
01-06-2010, 01:32 PM
Ok, so now I solved my last issue, but have hit the wall with this one... The following code produces this error:

MSSQL error: The name "XXX" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.


$sql = 'INSERT INTO tbl_jobs VALUES (';
$sql .= $_POST["company"];
$sql .= ',';
$sql .= $_POST["location"];
$sql .= ',';
$sql .= $_POST["title"];
$sql .= ',';
$sql .= $_POST["desc"];
$sql .= ',';
$sql .= $_POST["exper"];
$sql .= ',';
$sql .= $_POST["edu"];
$sql .= ',';
$sql .= $_POST["link"];
$sql .= ')';

In my troubleshooting, I verified that the variables are passing correctly, but it's treating it like a column name (according to the error). According to what I have seen, the syntax looks ok, but again, I am confused. I have googled this, but no luck so far.

This is not how php should be. You should listen to W1zzard's advise and keep it all in one string.

Second, strings need to be surrounded with single quotes which you haven't done. Show me your output.

Particle
01-14-2010, 09:12 AM
Single quotes. Escape any single quotes in the values themselves by converting them to double single quotes. That'll fix you in no time.