Page 1 of 1

PHP and mssql_query() - Internal Server 500 Error

Posted: Wed Dec 30, 2009 10:06 am
by mjkomidar
This is my first time using MSSQL with PHP and I have having an issue that I can't solve (I have used MySQL for years with no problems).

When I run the following script, I get a generic Internal Server 500 Error with no explanation. I ran another script to test the $_POST variables to make sure they get passed and that worked fine. Also, In other tests my db connection and db selection work just fine. Could there be an issue with my INSERT or mssql_query() statement?



<SCRIPT LANGUAGE = "PHP">

$server = '****';

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

mssql_select_db('db_jobs', $connect);

$sql = "INSERT INTO tbl_jobs
(
job_company,
job_location,
job_title,
job_desc,
job_exper,
job_edu,
job_link
)
VALUES
(
$_POST["company"],
$_POST["location"],
$_POST["title"],
$_POST["desc"],
$_POST["exper"],
$_POST["edu"],
$_POST["link"]
)";

$query = mssql_query($sql);


if(!$connect)
{
die('Something went wrong while connecting to MSSQL');
}

if(!$query)
{
die('Something went wrong while inserting data into the table');
}

</SCRIPT>

Re: PHP and mssql_query() - Internal Server 500 Error

Posted: Wed Dec 30, 2009 12:17 pm
by AbraCadaver
First off I don't have any idea what the <SCRIPT LANGUAGE = "PHP"> is. Second, you either need to escape the double-quotes in your query, or use single-quotes.

Re: PHP and mssql_query() - Internal Server 500 Error

Posted: Wed Dec 30, 2009 12:24 pm
by mjkomidar
AbraCadaver wrote:First off I don't have any idea what the <SCRIPT LANGUAGE = "PHP"> is. Second, you either need to escape the double-quotes in your query, or use single-quotes.

<SCRIPT LANGUAGE = "PHP"> is just another way to "open" a PHP script. I found it years ago and been using it ever since.

Can you clarify your second comment? I'm a wee bit confused. Sorry :-) I'm just a little rusty in certain areas. Thanks!

Re: PHP and mssql_query() - Internal Server 500 Error

Posted: Wed Dec 30, 2009 12:34 pm
by mjkomidar
mjkomidar wrote:
AbraCadaver wrote:First off I don't have any idea what the <SCRIPT LANGUAGE = "PHP"> is. Second, you either need to escape the double-quotes in your query, or use single-quotes.

<SCRIPT LANGUAGE = "PHP"> is just another way to "open" a PHP script. I found it years ago and been using it ever since.

Can you clarify your second comment? I'm a wee bit confused. Sorry :-) I'm just a little rusty in certain areas. Thanks!

I may have figured it out. I just replaced the " with ' and didn't get the 500 error. Now I recieved a different error that I need to work on. LOL, I can't believe I didn't notice it. I've been staring at the code for days. Thanks for the help!