PDA

View Full Version : MSSQL error: Invalid pseudocolumn "$_POST"



mjkomidar
01-02-2010, 10:01 PM
I have used MySQL and PHP for sever years with no problems, but this is my first time using MSSQL and PHP and I am having some trouble and can't seem to figure out what is wrong.

When running the follow script/SQL query, I get --> MSSQL error: Invalid pseudocolumn "$_POST"


$server = '***';

$connect = mssql_connect($server, 'sa', '***');

mssql_select_db('db_jobs', $connect);

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

$query = mssql_query($sql);

if (!$query)
{
die('MSSQL error: ' . mssql_get_last_message());
}


What is the problem?

It goes without saying that I'm able to connect to my server and perform other simple tasks, like create the database and tables using php, but I can't add data using the above script.

ahmad
01-03-2010, 05:43 PM
$sql = 'INSERT INTO tbl_jobs VALUES
(
{$_POST["id"]},
{$_POST["company"]},
{$_POST["location"]},
{$_POST["title"]},
{$_POST["desc"]},
{$_POST["exper"]},
{$_POST["edu"]},
{$_POST["link"]}
)';


When debugging, print out your strings:


echo $sql;

If you have issues with the above, try swapping the " with ' and vice versa.


I have used MySQL and PHP for sever years with no problems, but this is my first time using MSSQL and PHP and I am having some trouble and can't seem to figure out what is wrong.

When running the follow script/SQL query, I get --> MSSQL error: Invalid pseudocolumn "$_POST"


$server = '***';

$connect = mssql_connect($server, 'sa', '***');

mssql_select_db('db_jobs', $connect);

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

$query = mssql_query($sql);

if (!$query)
{
die('MSSQL error: ' . mssql_get_last_message());
}


What is the problem?

It goes without saying that I'm able to connect to my server and perform other simple tasks, like create the database and tables using php, but I can't add data using the above script.

W1zzard
01-04-2010, 08:19 AM
replace the ' around the sql statement with ". ' means no parsing of $... inside the text.
also put "" around the inserted variables

mjkomidar
01-06-2010, 07:12 AM
Here is the code that resolved my issue:

$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 .= ')';


HOWEVER, this now causes a new error which I will post in another post.

mjkomidar
01-06-2010, 07:21 AM
I am just amazed at the differences between MSSQL and MySQL when it comes to PHP. Oy!