繁体   English   中英

php sql插入没有结果

[英]php sql insert no result

我不能在php中插入查询。 在SQL插入..工作。

  $servername = "localhost";
    $username = "root";
    $password = "password";
    $dbname = "good_sc";
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    if ($conn) 
    {
        die("conn established:"); //works fine
    }
    $sql = "INSERT INTO order_items (orderid,customerid,goodid,order_price,quantity)
    VALUES
    ( '59',
      '2',
      '4',
      '55.0',
      '4')";

    }
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully <br/>";
    } else 
    {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

最后“if and else”代码没有显示任何内容。 没有结果,没有错误。 我可以直接使用SQL来执行此INSERT。 有用。 但不是在PHP中。 我可以从php和输出数据中选择。 但插入不起作用。 为什么? Apache 2.2.22 PHP 5.4.12 WinXPSP 3 32位。

这是我的桌子

create table order_items
(
  orderid int unsigned not null,
  customerid int unsigned not null,
  goodid char(13) not null, 
  order_price float(4,2) not null,
  quantity tinyint unsigned not null,
  primary key (orderid, goodid)
);

更改if上的条件。 如果你调用die你的脚本执行将被终止。

$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) 
{
    die("conn not established:"); //didnt work fine
}
1) There is an extra closing braces(}) before start of if 
($conn->query($sql) === TRUE) statement.
2)  if ($conn)  should be replace by  if (!$conn) because when it return false then script should be terminate but in your condition script being terminate on success connection. 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM