Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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));
}
share|improve this question
1  
is the connection running? "dbo" exists? and "Salesforce"? –  Igoel Feb 27 '14 at 10:16
    
@Igoel yes the connection is running. I am able to connect successfully. I added the connection string above in my edit. Is the error related to connecting to the db? –  Sarah Feb 27 '14 at 10:57
1  
He can´t find the table I think, so Salesforce exists or isn`t mistyped? –  Igoel Feb 27 '14 at 11:21
    
Thanks @Igoel, that was the issue. Solved it. +1 for pointing to the right direction! –  Sarah Feb 27 '14 at 11:23

1 Answer 1

I think your Query as wrong. Please check the query with right syntax.

$insertSql = "INSERT INTO tablename (ID,Name, Company, Email, Phone, Assets, Comm, Capability) VALUES (val1,val2,val3,val4.....)";

share|improve this answer
    
If you think the "?" are wrong....this is a prepared statement, so it´s fine what he did –  Igoel Feb 27 '14 at 10:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.