以下代码未被执行
(edited)
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
print "Hello world!";
$con = mysqli_connect($host,$uname,$pwd,$db) or die(mysqli_error());
$sql1="SELECT * FROM USERS WHERE username= 'aya'");
$result = mysqli_query($sql1);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
// json response array
$response = array("error" => FALSE);
$email = $_POST['username'];
$password = $_POST['password'];
$sql="SELECT * FROM USERS WHERE username= 'aya'";
if(mysqli_query($con,$sql))
{
echo json_encode($response);
}
?>
错误出现在这部分中,因为当我删除它时,链接会给出结果
$sql="SELECT * FROM USERS WHERE username= 'aya'") or die(mysqli_error())";
$result = mysqli_query($sql);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
答案 0 :(得分:1)
有问题的代码有明显的语法和逻辑错误。
如下所示更正您的代码:
...
// stop script execution with error message if db connection fails
$con = mysqli_connect($host, $uname, $pwd, $db) or die(mysqli_error());
$sql1 = "SELECT * FROM USERS WHERE username= 'aya'";
$result = mysqli_query($sql1);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
...
答案 1 :(得分:0)
正如你所说,错误出现在这一部分:
$sql="SELECT * FROM USERS WHERE username= 'aya'") or die(mysqli_error())";
正如您在第一行末尾所看到的,您只需删除双引号";
"
。
您还需要在(
之前添加"SELECT
,因此您的代码应为:
$sql= ("SELECT * FROM USERS WHERE username= 'aya'");
$result = mysqli_query($sql) or die(mysqli_error());
答案 2 :(得分:0)
更正后的代码:
$con = mysqli_connect($host,$uname,$pwd,$db);
$sql="SELECT * FROM USERS WHERE username='aya'";
$result = mysqli_query($sql) or die(mysqli_error());
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
答案 3 :(得分:0)
它的额外双引号&#39; &#34; &#39;分号前的第1行结束我删除了它。
$sql="SELECT * FROM USERS WHERE username= 'aya'") or die(mysqli_error());
$result = mysqli_query($sql);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}