为什么这会导致语法错误或$ _end错误?

时间:2013-05-23 12:46:27

标签: php sql syntax sql-update

<?php
if(isset($_POST['update']))
$dbhost = 'localhost';
$dbuser = 'XXXXX';
$dbpass = 'XXXXX';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

if(! get_magic_quotes_gpc() )
{
 $OrderID=addslashes ($_POST['OrderID']); 
 $trackingnumber= addslashes ($_POST['trackingnumber']);
 $trackingURL=addslashes ($_POST['trackingURL']); 
 $CustomerName=addslashes ($_POST['CustomerName']); 
 $LocationShipped=addslashes ($_POST['LocationShipped']); 
 $user_email=addslashes ($_POST['user_email']); 
 $ShipmentDate=addslashes ($_POST['ShipmentDate']);
 $ShipmentMode=addslashes ($_POST['ShipmentMode']);  
 $CurrentStatus=addslashes ($_POST['CurrentStatus']);
}
else
{
 $trackingnumber= $_POST['trackingnumber'];
 $trackingURL=$_POST['trackingURL']; 
 $OrderID=$_POST['OrderID']; 
 $CustomerName=$_POST['CustomerName']; 
 $user_email=$_POST['user_email']; 
 $LocationShipped=$_POST['LocationShipped']; 
 $ShipmentDate=$_POST['ShipmentDate'];
 $ShipmentMode=$_POST['ShipmentMode'];  
 $CurrentStatus=$_POST['CurrentStatus'];
}

$sql = "
    UPDATE
        ordertracking
    SET
        trackingnumber =$trackingnumber,
        `trackingURL` = '" . $trackingURL . "',
        `CustomerName` = '" . $CustomerName . "',
        `LocationShipped` = '" . $LocationShipped . "',
        `user_email` = '" . $user_email . "',
        `ShipmentDate` = '" . $ShipmentDate . "',
        `ShipmentMode` = '" . $ShipmentMode . "',
        `CurrentStatus` = '" . $CurrentStatus . "',
    WHERE
        OrderNo = $OrderID,

$result1 = mysql_query($query1);
mysql_select_db('XXXXXXX');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>

  

解析错误:语法错误,第46行/home/buyerhel/public_html/ordertracking/backend/processeditship.php中的意外T_STRING

请帮忙吗?

不确定问题是什么,但是因为我在我的项目的编辑部分的最后一步,它允许我更新表格,所以真的很令人沮丧。 我特意在这里省略了引号 - trackingnumber = $ trackingnumber, 所以这不是问题..

4 个答案:

答案 0 :(得分:2)

"中没有结尾符号$sql。应该是:

$sql = "
    UPDATE
        ordertracking
    SET
        trackingnumber =$trackingnumber,
        `trackingURL` = '" . $trackingURL . "',
        `CustomerName` = '" . $CustomerName . "',
        `LocationShipped` = '" . $LocationShipped . "',
        `user_email` = '" . $user_email . "',
        `ShipmentDate` = '" . $ShipmentDate . "',
        `ShipmentMode` = '" . $ShipmentMode . "',
        `CurrentStatus` = '" . $CurrentStatus . "'
    WHERE
        OrderNo = $OrderID"; // < missing ";

答案 1 :(得分:0)

您已使用,代替;而忘记了一些"

$sql = "
    UPDATE
        `ordertracking`
    SET
        `trackingnumber` = " . $trackingnumber . ",
        `trackingURL` = '" . $trackingURL . "',
        `CustomerName` = '" . $CustomerName . "',
        `LocationShipped` = '" . $LocationShipped . "',
        `user_email` = '" . $user_email . "',
        `ShipmentDate` = '" . $ShipmentDate . "',
        `ShipmentMode` = '" . $ShipmentMode . "',
        `CurrentStatus` = '" . $CurrentStatus . "',
    WHERE
        `OrderNo` = " . $OrderID; // ; instead of ,

$result1 = mysql_query($query1);

答案 2 :(得分:0)

两个问题

  1. 关闭双qoutes
  2. 在$ OrderID
  3. 之后删除尾随逗号

    所以改变

    $sql = "
    UPDATE
        ordertracking
    SET
        trackingnumber =$trackingnumber,
        `trackingURL` = '" . $trackingURL . "',
        `CustomerName` = '" . $CustomerName . "',
        `LocationShipped` = '" . $LocationShipped . "',
        `user_email` = '" . $user_email . "',
        `ShipmentDate` = '" . $ShipmentDate . "',
        `ShipmentMode` = '" . $ShipmentMode . "',
        `CurrentStatus` = '" . $CurrentStatus . "',
    WHERE
        OrderNo = $OrderID,
    

    $sql = "
    UPDATE
        ordertracking
    SET
        trackingnumber =$trackingnumber,
        `trackingURL` = '" . $trackingURL . "',
        `CustomerName` = '" . $CustomerName . "',
        `LocationShipped` = '" . $LocationShipped . "',
        `user_email` = '" . $user_email . "',
        `ShipmentDate` = '" . $ShipmentDate . "',
        `ShipmentMode` = '" . $ShipmentMode . "',
        `CurrentStatus` = '" . $CurrentStatus . "',
    WHERE
        OrderNo = $OrderID";
    

答案 3 :(得分:0)

只需更换50号线

   OrderNo = $OrderID";

通过此代码