Row insertion failed. Array

I am trying to insert items from a form into MSSQL via PHP but I am having some trouble, please see my code bellow and see if you can point me in the right direction as to my trouble. And I thank you in advance.
<?php  
$serverName = "Servername"; 
$uid = "423";   
$pwd = "Password";  
$databaseName = "423"; 

$connectionInfo = array( "UID"=>$uid,                            
                         "PWD"=>$pwd,                            
                         "Database"=>$databaseName); 
  
/* Connect using SQL Server Authentication. */  
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
  
// TRY TO CONNECT
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
if( $conn === false )  
{  
     echo "Could not connect.\n";  
     print_r( sqlsrv_errors() );  
}  

// DEFINE OUR VARIABLES
$today = date('c');
$phpgur = $_POST["gur"];
$phpbur = $_POST["bur"];

/* Set parameter values. */
$params = array($phpbur,$phpgur,$today); // 

/* Set up the parameterized query. */  
$tsql = "INSERT INTO 423.tss (bur,gur,un) VALUES (?,?,?,)";  

/* Prepare and execute the query. */  
$stmt = sqlsrv_query($conn, $tsql, $params);  
if( $stmt )  
{  
     echo "Row successfully inserted.\n";  
}  
else  
{  
     echo "Row insertion failed.\n";  
     print_r( sqlsrv_errors() );  
}  


echo "connectionInfo";
var_dump($connectionInfo);

echo "conn";
var_dump($conn);

echo "params";
var_dump($params);

echo "today is $today";

echo "stmt";
var_dump($stmt);

echo "tsql is $tsql";

/* Free statement and connection resources. */ 
sqlsrv_free_stmt($stmt);  

Open in new window



I revive the following error:
Row insertion failed. Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '423.'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '423.'. ) ) connectionInfoarray(3) { ["UID"]=> string(3) "423" ["PWD"]=> string(60) "2daf7bedb637d0c77748462f3a073e0a8d895c2a31a5ac3452ad6675fa1a" ["Database"]=> string(3) "423" } connresource(5) of type (SQL Server Connection) paramsarray(3) { [0]=> string(3) "bur" [1]=> string(3) "gur" [2]=> string(25) "2017-03-07T20:09:54-05:00" } today is 2017-03-07T20:09:54-05:00stmtbool(false) tsql is INSERT INTO 423.tss (bur,gur,un) VALUES (test10,test10,12/12/12)
Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, boolean given in G:\s\wunderlist-api-demo-master\brace\connect4.php on line 63

Open in new window


I am using server 2012 R2,
SQL server 2008 ( I believe)
PHP 5.6 on IIS
Thank you in advance let me know if you need more info.
LVL 1
Joe DanyiOwnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Just a "swag" guess, but try omitting the last comma.

Not this:
$tsql = "INSERT INTO 423.tss (bur,gur,un) VALUES (?,?,?,)";  

Instead this:
$tsql = "INSERT INTO 423.tss (bur,gur,un) VALUES (?,?,?)";
0
Joe DanyiOwnerAuthor Commented:
Alas im afraid not :(
 
i did make that change to the script tho.

Any further input appreciated
0
Joe DanyiOwnerAuthor Commented:
http://stackoverflow.com/questions/24512094/connecting-php-to-ms-sql-server
it could be because of use of "thing" instead of using 'thing' maybe?
 "to avoid escapingg you could also use single quotes ' instead of double quotes ". Then PHP does not resolve variables within the string. (see this question)"
0
Ray PaseurCommented:
What is the name of your table?  That name needs to go in place of "423.tss" in the query.  In most database activities there are a few important pieces.  The database name is first, and the table name is next.  These are sometimes written like this:

databaseName.tableName

In your case, it looks like the databaseName is part of the connection information, so it's probably OK to omit that (guessing a bit here... I know it's OK to omit the databaseName in MySQL)

I don't think the quotes are an issue here.  Take a moment to learn how quotes work in PHP, then please post the complete script exactly as you have it now, thanks.
https://www.experts-exchange.com/articles/12241/Quotation-Marks-in-PHP.html

Also, have you considered using MySQL instead of sqlsrv?  If there is a reason why you would reject MySQL, it might be worth discussing.  MySQL is about 1,000 times more widely used than sqlsrv, so it's easier to find good examples and competent help.  A quick lifetime search of E-E finds 727 answers about sqlsrv, and over 100,000 about MySQL.

And to the issue of good examples, when you go to StackOverflow with elementary questions, such as "why is my query broken" you probably want to noodle around the site a bit, using succinct keywords to search.  When you get to the more popular questions and answers, you're much more likely to find something worthwhile!  If you're looking at the question and answers and you're seeing low numbers, it means the question and the answers are marginally useful at best.  It's probably wise to stay away from things like that.
Lame question, lame answer, nobody does things this way
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Try putting your database name in square brackets

$tsql = "INSERT INTO [423.tss] (bur,gur,un) VALUES (?,?,?)";  

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.