php sql插入没有结果
我不能用php进行插入查询。在SQL插入中。。工作php sql插入没有结果,php,mysql,Php,Mysql,我不能用php进行插入查询。在SQL插入中。。工作 $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "good_sc"; $conn = mysqli_connect($servername, $username, $password, $dbname); if ($conn) { die("conn establ
$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上的条件。 如果调用
die
,脚本执行将终止
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn)
{
die("conn not established:"); //didnt work fine
}
因此,如果连接成功,您的脚本将死亡,并且您希望它在连接成功后做更多的事情?:-)谢谢谢谢谢谢谢谢
$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.