我是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 (!$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";
?>
答案 0 :(得分:1)
您没有引用“ashish”,因此数据库会尝试将其解析为关键字并失败。您应该能够看到使用mysql_error()或在PHP中调用的任何内容: - )