Problems with connecting to MS-SQL
Posted: Sun Aug 10, 2014 7:07 am
Probably a problem seen many times before, and I have spent the last three days debugging this but it has me beat.
A form on a web page, passing using a POST command, to this php page, to put the data into a table in my Microsoft SQL server. Server is running on same machine as IIS7. Authentication is SQL authentication. Passwords and usernames are correct (and removed and replaced with XXX's here).
Someone please spot my obvious error. All I get on clicking submit on the form page is a blank screen...
A form on a web page, passing using a POST command, to this php page, to put the data into a table in my Microsoft SQL server. Server is running on same machine as IIS7. Authentication is SQL authentication. Passwords and usernames are correct (and removed and replaced with XXX's here).
Someone please spot my obvious error. All I get on clicking submit on the form page is a blank screen...
Code: Select all
<?php
//pull form fields into php variables
echo "This script is working ...."
$ChapterNo = $_POST['ChapterNo'];
$MeetDay = $_POST['MeetingDay'];
$MeetMonth = $_POST['MeetingMonth'];
$MeetYear = $_POST['MeetingYear'];
$Work = $_POST['Work'];
$uid = "XXXXXX"
$pwd = "XXXXXX"
//connect to sql
$serverName = "(local)";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>"Companions");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
// Input into database
$query = "INSERT INTO dbo.Meetings (ChapterNo,MeetDay,MeetMonth,MeetYear,Work) VALUES ('$ChapterNo','$MeetDay','$MeetMonth','$MeetYear','$Work')GO";
$result = sqlsrv_query($dbc,$query)or die('Error querying MSSQL database');
//close to sql
sqlsrv_close($link);
echo $ChapterNo . 'Thanks for using the New Web Form, you submission has been received<br />';
echo 'If you need change this request please log in to the Helpdesk portal<br />';
echo 'Thank you <br />';
echo 'The Helpdesk';
?>