[英]php sql insert no result
I can`t do insert query in php. 我不能在php中插入查询。 In SQL insert.. works.
在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;
}
Last "if and else" code show nothing. 最后“if and else”代码没有显示任何内容。 No result, no error.
没有结果,没有错误。 I can do this INSERT by using SQL directly.
我可以直接使用SQL来执行此INSERT。 It works.
有用。 But not in php.
但不是在PHP中。 I can select from php and output data.
我可以从php和输出数据中选择。 but insert does not work.
但插入不起作用。 Why?
为什么? Apache 2.2.22 PHP 5.4.12 WinXPSP 3 32bit.
Apache 2.2.22 PHP 5.4.12 WinXPSP 3 32位。
This is my table 这是我的桌子
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)
);
Change the condition on your if. 更改if上的条件。 If you call
die
your script execution will be terminated. 如果你调用
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.