我想获取mysqli查询结果的行数,但此代码不返回任何内容。
$mysqli = new mysqli('127.0.0.1', 'root', 'pass', 'db');
$sql = "SELECT * FROM user WHERE username = '".$_POST['username']."'";
$result = $mysqli->query($sql);
if($result->num_rows == 0){
echo "0";
}else{
$query = "INSERT INTO user (username,password) VALUES ('".$_POST['username']."','".md5($_POST['pass'])."')";
if($mysqli->query($query)){
echo "1";
}else{
echo "2";
}
}
答案 0 :(得分:0)
$mysqli = new mysqli('127.0.0.1', 'root', 'pass', 'db');
$sql = "SELECT * FROM user WHERE username = '".$_POST['username']."'";
$result = $mysqli->query($sql);
$rowcount=mysqli_num_rows($result);
echo $rowcount;
if($rowcount == 0)
{
echo "0";
}
else
{
$query = "INSERT INTO user (username,password) VALUES ('".$_POST['username']."','".md5($_POST['pass'])."')";
if($mysqli->query($query)
{
echo "1";
}
else
{
echo "2";
}
}