How to check if Id is already exist in mysql database using php -


im trying use code not working reason...

errorcode: warning: mysql_num_rows() expects parameter 1 resource, line number 27

the code im using:

<?php  include("db.php");      $lname = $_post['lname'];     $fname = $_post['fname'];     $mname = $_post['mname'];     $adress = $_post['address'];     $gender = $_post['gender'];     $nationality = $_post['nationality'];     $religion = $_post['religion'];     $contact = $_post['contact'];     $email = $_post['email'];     $school = $_post['school'];     $year = $_post['year'];     $schooladd = $_post['schooladd'];     $schoolid = $_post['schoolid'];     $database = $school;     mysql_select_db("$database", $con);      $id = str_replace(' ', '_', $lname.$schoolid);      //check if id exist    $check = mysql_query("select * wup schoolid = '$schoolid'");       if (mysql_num_rows($check) > 0) {    echo "user exist";      }    else     {     $sql = "insert scholars (id, schoolid, lastname, firstname, middlename, address, gender, nationality, religion, contact, email, school, year, schooladdress)      values ('$id', '$schoolid', '$lname', '$fname', '$mname', '$adress', '$gender',     '$nationality', '$religion', '$contact', '$email', '$school', '$year', '$schooladd')";}     mysql_query($sql,$con);    mysql_close($con);   ?> 

the error warning: mysql_num_rows() expects parameter 1 resource means query had syntax error.

on successful execution of query, result variable $check contain results on can perform mysql_num_rows.

if fails, value of $check false , mysql_num_rows fail.

avoid using mysql functions, because deprecated. use mysqli functions instead


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -