php中的mysqli_num_rows错误。请帮忙 [英] Mysqli_num_rows error in php. Please help

查看:75
本文介绍了php中的mysqli_num_rows错误。请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的拼贴项目编写了php代码。我使用了php / mysql的mysqli_num_rows()函数,我得到了这个错误: mysqli_num_rows()期望参数1是mysqli_result boolean在中给出



这是我的全部代码:

i have write the php code for my collage project. i used mysqli_num_rows() function of php/mysql and i get this error:mysqli_num_rows() expects parameter 1 to be mysqli_result boolean given in

here is my whole code:

<pre><?php require_once('inc/top.php');?>
 </head>
 <body>
 <!--navbae-->
		<?php require_once('inc/nav.php');?>
<!--End navbar-->
<div class="container-fluid">
	<div class="row">
		<?php require_once('inc/sidebar.php');?><!--end sidebar-->
		<div class="col-md-9">
			<h1> Add Users <small>Add New Users Profile</small></h1><hr>
			<ol class="breadcrumb">
              <li><a href="index.php"> Dashbord</a></li>
			  <li class="active"> Add Users</li>
			</ol>
			<?php
                if(isset($_POST['submit'])){
                    $name = mysqli_real_escape_string($cn, $_POST['name']);
                    $username = mysqli_real_escape_string($cn, $_POST['user-name']);
                    $username_trim = preg_replace('/\s+/','',$username);
                    $email = mysqli_real_escape_string($cn,$_POST['email']);
                    $password = mysqli_real_escape_string($cn,$_POST['password']);
                    $role = $_POST['role'];
                    $image = $_FILES['image']['name'];
                    $image_tmp = $_FILES['image']['tmp_name'];
                  //  $check_query = "SELECT * FROM user WHERE user_name = '$username' or email = '$email'";
                    $check_run = mysqli_query($cn,"SELECT * FROM `user` WHERE `user_name` = '$username' or `email` = '$email'");
                    if(empty($name) or empty($username) or empty($email) or empty($password) or empty($image)){
                        $error = "ALL (*) FEILDS ARE REQUIRED";
                    }
                    else if($username != $username_trim)
                    {
                        $error = "Don't use spaces in Username";
                    }
                    else if(mysqli_num_rows($check_run)>0)
                    {
                        $error = "Username or email allready Exists";
                    }
                    else
                    {
                        $msg = "Success";
                    }
                }
            ?>
			<div class="row">
			    <div class="col-md-8">
                        <form action="" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="name">Name:*</label>
                            <?php
                                if(isset($error)){
                                    echo "<span class='pull-right' style='color:red;'>$error</span>";
                                }
                            ?>
                            <input type="text" name="name" id="name" class="form-control" placeholder="Name">
                        </div>
                        <div class="form-group">
                            <label for="user_name">User Name:*</label>
                            <input type="text" name="user-name" id="user-name" class="form-control" placeholder="User Name">
                        </div>
                        <div class="form-group">
                            <label for="email">E-mail:*</label>
                            <input type="text" name="email" id="email" class="form-control" placeholder="E-mail">
                        </div>
                        <div class="form-group">
                            <label for="password">Password:*</label>
                            <input type="password" name="password" id="password" class="form-control" placeholder="Password">
                        </div>
                        <div class="form-group">
                            <label for="role">Role:*</label>
                            <select name="role" id="role" class="form-control">
                                <option value="author">Author</option>
                                <option value="admin">Admin</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="profile">Profile Picture:*</label>
                            <input type="file" name="image" id="image">
                        </div>
                        <input type="submit" value="Add user" name="submit" class="btn btn-primary">
                        </form>
			    </div>
			    <div class="col-md-4"></div>
			</div>
		</div>
	</div>
</div>
<?php require_once('inc/footer.php');?>





ih我将获得最佳解决方案。

提前感谢。



我尝试过的方法:



我会尝试一些替代但它不起作用。



i hope i'll get the best solution.
thanks in advance.

What I have tried:

i'd try some alternation but it dosen't work.

推荐答案

_POST [' submit'])){
_POST['submit'])){


name = mysqli_real_escape_string(
name = mysqli_real_escape_string(


cn,


这篇关于php中的mysqli_num_rows错误。请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆