-1

I am trying to submit data through form and came across the below error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given ..

Please find the code I have tried.

//connection end to my data server.

if(isset($_POST["submit"])) {

     $user_name = $_POST['name'];
     $user_email = $_POST['email'];
     $user_skype = $_POST['skype'];

    if($user_name==""){
        echo "<script>alert('please enter your user name!')</script>";
        exit();
    }

    if($user_email==""){
        echo "<script>alert('please enter your email!')</script>";
        exit();
    }       

    if($user_skype==""){
        echo "<script>alert('please enter your skype id.')</script>";
        exit();
    }   

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

    $run = mysql_query($check_email);

    if(mysql_num_rows($run)>0){

    echo "<script>alert('Your email $user_email address already exist. please try another.')</script>";
    exit();

    }

    $query= "insert into binary (user_name, user_email, user_skype) values('$user_name','$user_email','$user_skype')";

    if(mysql_query($query)){
    echo "<script>window.open('success.html','_self')</script>";
    }

}

?>
Unihedron
  • 10,902
  • 13
  • 62
  • 72
  • Please explain me details i am new in php.. :( – Tania Parven Oct 18 '14 at 10:24
  • For a start, consider moving away from the deprecated `mysql_*` functions and use something like MySQLi instead: it's far more secure. http://php.net/manual/en/book.mysqli.php – Mitya Oct 18 '14 at 10:25

3 Answers3

1

binary is sql reserrve word

use backticks around it

$check_email = "select * from `binary` where user_email = '$user_email' ";

check this link for sql reserve word. http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

and learn mysqli_ function or P.D.O as mysql is deprcitaeted

arif_suhail_123
  • 2,509
  • 2
  • 12
  • 16
0

Please update your query: It should be

$check_email = "select * from `binary` where user_email = '".$user_email."' ";
John Snow
  • 61
  • 6
0

it seems select query returns boolean false because

$check_email = "select * from binary where user_email = '$user_email' "

where user_email = '$user_email' can not parse value of '$user_email' because variable inside single quat does not parsed with their value

use:- where user_email = ".$user_email; and everything should work