代码不执行任何操作
include 'connection.php';
$user = $_POST['user'];
$pass = $_POST['pass'];
$verify = "SELECT * FROM `contas` WHERE `user` = 'Richard'";
$create = "INSERT INTO `tibitos`.`contas` (`pass` ,`user`) VALUES ('$pass', '$user');";
if($con->query($verify)){
echo mysqli_num_rows($verify);
}else{
echo die($con->error);
}
?>
我正在尝试使代码显示“理查德”(Richard)中存在的列数,虽然有,但php不显示任何内容
我的代码有什么错误?请帮助我
如果我做错了什么,请纠正我
答案 0 :(得分:0)
假设您建立了
$con= new mysqli("localhost", "my_user", "my_password", "my_table");
在connection.php
<?php
include 'connection.php';
$user = $_POST['user'];
$pass = $_POST['pass'];
$verify = "SELECT * FROM `contas` WHERE `user` = 'Richard'";
$create = "INSERT INTO `tibitos`.`contas` (`pass` ,`user`) VALUES ('$pass', '$user');";
// query returns mysqli result and not false
if( $result = $con->query($verify) ){
// Assign and print out Numbers of row(s)
echo $count = $result->num_rows;
// Check your count and do ...
if( $count == 0 ) {
// insert values or whatever
$result = $con->query($create);
} else {}
} else {
// on error
exit();
}
?>