Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\registration\r­egistration.php on line 66

i already tried mysqli_error() and does not fix this problem

<html>
    <head>
        <title>Registration Form</title>
    </head>

<body>
<form method='post' action='registration.php'>
    <table width='400' border='5' align='center'>

        <tr>
        <td><h1>Registration Form</h1></td>

    </tr>

    <tr>
        <td>User Name:</td>
        <td><input type='text' name='name'/></td>
    </tr>

    <tr>
        <td>Password:</td>
        <td><input type='password' name='pass'/></td>
    </tr>
    <tr>
        <td>Email:</td>
        <td><input type='text' name='email'/></td>
    </tr>
    <tr>
        <td><input type='submit' name='submit' value='Sign Up'/></td>

    </tr>

    </table>
</form>  
</body>
</html>
<?php
mysql_connect("localhost","root","");
mysql_select_db("user_db"); 
    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 Username')</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 *select* from users where 
    user_email='$user_email'";

    $run = mysql_query($check_email);

    if(mysql_num_rows($run)>0){

    echo"<script>alert('Email $user_email 
    is already exist in our databse, please try another 
    one')</script>";
    exit();
    }

    $query = "insert into users 
    (user_name,user_pass,user_email) values('
    $user_name','$user_pass','$user_email')";
    if(mysql_query($query)){

    echo "<script>alert('Registration 
    Successfull!')</script>";
    }

}



?>

Recommended Answers

All 20 Replies

$check_email="select *select* from users where user_email='$user_email'";

What is *select* doing there?

i tried deleting it but it does not solve the error

still the same error

Using mysqli_error () won't solve the problem. Rather, it'll aid in diagnosing it. What is the output received when you kill on mysqli_error? The PHP error you're receiving is due to a bad query, so the output of mysqli_error is critical.

You're using the mysql extension, so you should be using mysql_error() (without the i).

$check_email = "select * from users where user_email='$user_email'";
$run = mysql_query($check_email) or die(mysql_error());

It says no database selected

I solve thr problem but it wont echo out "Successfull"

Which second query?

I added or die(msql_error()); and it does not work it gave me error

Specify?

I can't guess what you did, so show the code you used and show the error message.

Off-topic: read this.

`

if(mysql_query($query)) {

    echo "<script>alert('Registration 
    Successfull!')</script>";
    or
    die(mysql_error());

`

$result = mysql_query($query) or die(mysql_error());
if ($result)
{
    echo "<script>alert('Registration Successfull!')</script>";
}

it works sometimes only

$query = "insert into users 
    (users_name,users_pass,users_email) values('
    $users_name','$users_pass','$users_email')";

if(mysql_query($query)) {
    $result = mysql_query($query) or die(mysql_error());
    if ($result)
{
    echo "<script>alert('Registration Successfull!')</script>";
}

Where should i put it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.