代码用于在数据库中插入用户数据
上的错误$run = mysqli_query($con,$check_email);
注意:类mysqli_result的对象无法转换为int
和
警告:mysqli_num_rows()期望参数1为mysqli_result,boolean
<?php
$con = mysqli_connect("localhost","root","","users_db");
if (mysqli_connect_errno())
{
echo 'connection was not established'. mysqli_connect_error();
}
if(isset($_POST['submit'])){
$user_name = $_POST['name'];
$user_pass = $_POST['pass'];
$user_email = $_POST['email'];
if($user_name==''){
echo "<script>alert('please Enter your Nmae!')</script>";
exit();
}
if($user_pass==''){
echo "<script>alert('please Enter your password!')</script>";
exit();
}
if($user_email==''){
echo "<script>alert('please Enter your Email!')</script>";
exit();
}
$check_email = "select * from users where user_email='$user_email'";
$run = mysqli_query($con,$check_email);
if(mysqli_num_rows($run>0)){
echo "<script>alert('Email $user_email is already exist in database please try another one')</script>";
exit();
}
$query = "insert into users(user_name,user_pass,user_email) values ('$user_name','$user_pass','$user_email')";
if(mysqli_query($con,$query)){
echo "<script>alert('Registration completed')</script>";
}
else{
echo"<script>alert('Data not inserted')</script>";
}
}
?>
答案 0 :(得分:1)
语法错误
if(mysqli_num_rows($run>0)){
这应该是
if(mysqli_num_rows($run) > 0){
^ should be moved
这应该可以解决这两个错误。
答案 1 :(得分:-1)
你在mysqli_num_rows中犯了小错误。
从:改变:
if(mysqli_num_rows($run>0)){
到
if(mysqli_num_rows($run) > 0){