I am trying to insert data into my database table in SQL Server. I am able to connect to the database and while inserting I get the following error:
Errors: Array ( [0] => Array ( [0] => 42S02 [SQLSTATE] => 42S02 [1] => 208 [code] => 208 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'dbo.Salesforce'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'dbo.Salesforce'. ) )
To keep things simple, I have hardcoded the values (instead of picking on form submit) that need to be inserted into the table:
/*Insert data.*/
$insertSql = "INSERT INTO dbo.Salesforce (ID,Name, Company, Email, Phone, Assets, Comm, Capability)
VALUES (?,?,?,?,?,?,?,?)";
/* Construct the parameter array. */
$ID = 5;
$Name = "Sarah";
$Company = "Track24";
$Email = "[email protected]";
$Phone = "+xxxxxx";
$Assets = "Vehicles";
$Comm = "GSM";
$Capability = "IVMS";
$params1 = array($ID,
$Name,
$Company,
$Email,
$Phone,
$Assets,
$Comm,
$Capability);
$stmt = sqlsrv_query($conn, $insertSql, $params1);
if($stmt === false)
{
die('Errors: ' . print_r(sqlsrv_errors(), TRUE));
}
else
{
echo '<br clear="all"><label style="color:red;">Thank you for your details.</label>';
}
The fields that are called above are not all the fields of the table. There are a few more but since they allow null
values, I did not include them. I have googled for this error but unable to understand what it actually means and where is the issue! Any pointers?
EDIT 1: Successfully connects through:
/* Specify the server and connection string attributes. */
$serverName = "xxxx-PC\SQLExpress";
$connectionOptions = array("Database"=>"Salesforce");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}