Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts

    Warning on mysql_num_rows!

    I created a registration form nd I have perfromed a check to see if the email address and the username already exist.

    Here are my codes:
    PHP Code:
    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    if (isset(
    $_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) {
    //Assignng variables        
    $firstname mysql_real_escape_string(stripslashes($_POST['fname']));
    $lastname mysql_real_escape_string(stripslashes($_POST['lname']));    
    $email mysql_real_escape_string(stripslashes($_POST['emailr']));
    $uname mysql_real_escape_string(stripslashes($_POST['user']));
    $pwd mysql_real_escape_string(stripslashes($_POST['pass']));
    $pmdmd5($pwd);
    //Database
    $connect mysql_connect('localhost''root''') or die ('Connection Failed');
    mysql_select_db('registration'$connect) or die ('Connection Failed');

    //Registration codes

    if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) {
    echo 
    '<p class="error">All fields are required to fill!</p>';
    return 
    false;
    } elseif (
    strlen($firstname) && (strlen($lastname) < '2')) {
    echo 
    '<p class="error">Invalid first name or last name!</p>';
    return 
    false;
    } elseif (
    filter_var($firstnameFILTER_VALIDATE_INT) || (filter_var($lastnameFILTER_VALIDATE_INT))) {
    echo 
    '<p class="error">First name or last name cannot be integers!</p>';
    return 
    false;
    } elseif (!
    filter_var($emailFILTER_VALIDATE_EMAIL)) {
    echo 
    '<p class="error">Email address not valid!</p>';
    return 
    false;    
    } elseif (
    strlen($uname) && (strlen($pmd) < '6' )) {
    echo 
    '<p class="error">Username or password must be minimum 6 characters!</p>';
    return 
    false;
    } else {
    $verify "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'";
    if(
    mysql_num_rows($verify) !== 0)
    {
    echo 
    '<p class="fail">This email or username is already taken!</p>';
    } else {
    $query "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')";
    mysql_query($query$connect);
    echo 
    '<p class="fail">Successful!</p>';
    }
    }
    }
    }
    ?>
    The codes are working, and the check is being performed, but I am getting this warning:

    Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\xampp\htdocs\miniimagehosting\register.php on line 61


    Why?

  • #2
    New Coder
    Join Date
    Feb 2012
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    PHP Code:
    ...
    $verify "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'";
    if(
    mysql_num_rows($verify) !== 0
    ... 
    mysql_num_rows() should have a mysq result, not raw sql

    PHP Code:
    ...
    $verify "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'";

    //e.q
    $result mysql_query($verify);

    if(
    mysql_num_rows($result) !== 0
    ... 

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    I tried but does not work..it is still registering....

  • #4
    New Coder
    Join Date
    Feb 2012
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    This code which you have posted has 46 lines, but you get error on 61.
    Did you post right file ?

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    because the rest of the codes above are HTML..

  • #6
    New Coder
    Join Date
    Feb 2012
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    are you still getting this error when you use mysql_query($verify) ?

  • #7
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    mysql_real_escape_string must be done AFTER connecting to the database


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •