这个让我难过了一会儿,我看不出为什么会收到这个错误。这是我的代码
<?php
include('include/auth.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['submit']))
{
$serverName = "localhost";
$connectionInfo = array( "Database"=>"db", "UID"=>"sa", "PWD"=>"****");
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$pathfinderid = $_POST['pathfinderid'];
$locationid = $_POST['locationid'];
$status = $_POST['status'];
$statusnote = $_POST['statusnote'];
$user = $_SESSION['SESS_USER'];
$date = new DateTime();
$ims = 'New Device Added';
if(empty($pathfinderid) || empty($locationid) || empty($status) || empty($statusnote)) {
echo "<div id='source'><p style='color:red;'>Please complete all fields</p></div>";
}
else
{
//SQL to check if pathdnder exsists
$stmt = sqlsrv_query( $conn, "SELECT * FROM devices WHERE pathfinderid='$pathfinderid'");
//If statement to check rows
if ($stmt) {
$rows = sqlsrv_has_rows( $stmt );
if ($rows === true) {
echo "<div id='source'><p style='color:red';>PathfinderID already exists</div>";
}
else
{
//Insert in to Devices Table
$tsql="INSERT INTO devices (pathfinderid, locationid, addeddate, status, creation_date, status_note) VALUES (?,?,?,?,?,?)";
$var = array ($pathfinderid, $locationid, $date, $status, $date, $statusnote);
if (!sqlsrv_query($conn, $tsql, $var)) {
die('Error: ' . sqlsrv_errors());
}
//Insert in to Transaction Log
$tsql="INSERT INTO transaction_log (Date, IMS, PathfinderID, LocationID, TransactionNotes, ManagedBy) VALUES (?,?,?,?,?,?,?)";
$var = array ($date, $ims, $pathfinderid, $locationid, $statusnote, $statusnote, $user);
if (!sqlsrv_query($conn, $tsql, $var)) {
die('Error: ' . sqlsrv_errors());
}
//Insert in to Movment Log
$tsql="INSERT INTO movement_log (pathfinderid, locationid, status, update_timestamp, addeddate, status_note) VALUES (?, ?, ?, ?, ?, ?')";
$var = array ($pathfinderid, $locationid, $status, $date, $date, $statusnote);
if (!sqlsrv_query($conn, $tsql, $var)) {
die('Error: ' . sqlsrv_errors());
}
//Display the confirmation messgae
echo "<div id='source'><p style='color:green;'>Device Added</p></div>";
}
}
}
}
&GT;
错误在第52行标记为beng:
//Insert in to Transaction Log
$tsql="INSERT INTO transaction_log (Date, IMS, PathfinderID, LocationID, TransactionNotes, ManagedBy) VALUES (?,?,?,?,?,?,?)";
$var = array ($date, $ims, $pathfinderid, $locationid, $statusnote, $statusnote, $user);
if (!sqlsrv_query($conn, $tsql, $var)) {
die('Error: ' . sqlsrv_errors());
}
有什么想法吗?我能想到的唯一一件事就是因为我正在重用变量名吗?
答案 0 :(得分:2)
你有一个双变量($ statusnote)
//Insert in to Transaction Log
$tsql="INSERT INTO transaction_log (Date, IMS, PathfinderID, LocationID, TransactionNotes, ManagedBy) VALUES (?,?,?,?,?,?,?)";
$var = array ($date, $ims, $pathfinderid, $locationid, $statusnote, $statusnote, $user);
if (!sqlsrv_query($conn, $tsql, $var)) {
die('Error: ' . sqlsrv_errors());
}
应该是
//Insert in to Transaction Log
$tsql="INSERT INTO transaction_log (Date, IMS, PathfinderID, LocationID, TransactionNotes, ManagedBy) VALUES (?,?,?,?,?,?)";
$var = array ($date, $ims, $pathfinderid, $locationid, $statusnote, $user);
if (!sqlsrv_query($conn, $tsql, $var)) {
die('Error: ' . sqlsrv_errors());
}