没有得到PHP MAMP MySQL查询的任何结果
我是PHP的初学者。我试图在我的php文件中运行以下代码,但没有得到任何结果,尽管数据在我的SQL表中以相同的条目出现没有得到PHP MAMP MySQL查询的任何结果,php,mamp,Php,Mamp,我是PHP的初学者。我试图在我的php文件中运行以下代码,但没有得到任何结果,尽管数据在我的SQL表中以相同的条目出现 <?php echo "this is the start"; $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "PW3"; $conn = mysqli_connect($servername, $username, $password, $dbname); if
<?php
echo "this is the start";
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "PW3";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
echo "Unable to connect to databse";
die("Connection failed: " . mysqli_connect_error());
}
else {
echo "Connected";
if(!empty($_POST["username"]) && !empty($_POST["password"])){
$username=$_POST['username'];
//echo "$username";
$sql="SELECT fullname FROM `users` WHERE username=ashish";
$result1=mysqli_query($conn,$sql);
print_r($result1);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result1);
echo "$count";
}
}
echo "<br>this is the end";
?>
您没有引用ashish,因此数据库将尝试将其作为关键字进行解析,但失败。您应该能够使用mysql\u error或PHP中的任何调用来看到这一点:-将WHERE username=ashish更改为WHERE username='ashish',看看这是否有帮助。否则,发布返回的错误消息。@jeff:我得到$result1的结果,但echo$count仍然没有结果。另外,如果我想这样给出:$sql=从username=$username的用户中选择fullname;它在这里也不会有任何结果。@ashishkumar你的意思是你在打印后什么也得不到?或者你得到$count或0或其他什么?@Albert221:它根本不显示结果。既不是0也不是别的。我不明白。您是否收到任何输出?你收到打印输出了吗?还是什么都没得到?但为什么echo$count没有;不打印任何内容?因为查询错误,所以row_结果返回NULL,所以$count为空。