PHP for MSSQL插入运行但没有插入数据

时间:2017-02-24 23:36:20

标签: php sql sql-server

我有一个PHP脚本试图INSERT将数据形成MSSQL数据库。当我运行脚本时,脚本成功运行,但INSERT似乎没有发布数据。以下是相关代码:

<?php
//collect data from form
$username  = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname  = $_POST['lastname'];
$address   = $_POST['address'];
$city      = $_POST['city'];
$state     = $_POST['state'];
$zip       = $_POST['zip'];
$telephone = $_POST['telephone'];
$email     = $_POST['email'];
$password  = $_POST['password'];

$serverName     = "192.168.1.1"; //serverName\instanceName
$connectionInfo = array( "Database"=>"mydatabase", "UID"=>"username", "PWD"=>"password");
$conn           = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     $sql    = "INSERT INTO Member_Details (FirstName,LastName,Address,City,State,Zip_Code,Telephone,Email,User_Name,Password,Is_Validated) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
     $params = array($firstname,$lastname,$address,$city,$state,$zip,$telephone,$email,username,$password,0);
     $stmt   = sqlsrv_query( $conn, $sql, $params);
     echo "You were successfully registered for user name " . $username;
}else {
     echo "Something went wrong";
}
?>

我已经确认通过运行脚本时传递的消息成功传递了表单数据。

任何建议将不胜感激! 麦克

1 个答案:

答案 0 :(得分:0)

据我记忆,你必须在前面加上dbo。 (或表的所有者的任何东西)到表名。

insert into dbo.tablename (cols) values (vals)