-2

Errors:

Warning: mysql_query() expects parameter 1 to be string, object given in C:\xampp\htdocs\social_network\functions\functions.php on line 20

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\social_network\functions\functions.php on line 21

I am using to connect:

$con = mysqli_connect("localhost","root","","social_network") or die("Connection was not established");

Code:

function InsertUser(){
    global $con;
if(isset ($_POST['sign_up'])){

    $name = $_POST['u_name'];
    $psss = $_POST['u_pass'];
    $email = $_POST['u_email'];
    $country = $_POST['u_country'];
    $gender = $_POST['u_gender'];
    $b_day = $_POST['u_birthday'];
    $name = $_POST['u_name'];
    $date = date("d-m-y");
    $status = "unverified";
    $posts = "No";

    $get_email = "select * from users where user_email='$email'";
    $run_email = mysql_query($con,$get_email);
    $check = mysql_num_rows($run_email);

    if($check==1){

        echo "<script>alert ('Email is already registered, please try another one!')</script>";
        exit();
    }

}
}

?>
  • Check this :- http://php.net/manual/en/function.mysql-query.php also this :- http://stackoverflow.com/questions/8806148/mysql-query-expects-parameter-1-to-be-string-resource-given – Vikrant Sep 24 '16 at 14:13
  • You need to debug your code. 1. `var_dump($con)` within your function and check the value you're getting. 2. Use `mysql_error()` function >> `$run_email = mysql_query($con,$get_email); or die(mysql_error())` – Indrasis Datta Sep 24 '16 at 14:15
  • no idea which API you're using to connect with. – Funk Forty Niner Sep 24 '16 at 14:21
  • $con = mysqli_connect("localhost","root","","social_network") or die("Connection was not established"); – Anna Lucado Sep 24 '16 at 14:29
  • do spend the time reading the manuals on given MySQL APIs. Your bit about *"ADHD and dyslexia"* is a crock. I've seen the same thing posted not long ago. ADHD and dyslexia are no excuse. I also have a case of dyslexia (fact) and that never stopped me from using the right syntax. – Funk Forty Niner Sep 24 '16 at 14:34

1 Answers1

0
$run_email = mysql_query($get_email,$con);

FYI mysql driver has been deprecated, you must use mysqli or PDO.

  • sure, that's IF they're using the MySQL_ API to connect with and we don't know that for certain. – Funk Forty Niner Sep 24 '16 at 14:21
  • She had written mysql statements and not mysqli or pdo statements, so she must have used mysql driver. –  Sep 24 '16 at 14:25
  • Your syntax is correct for using the MySQL_ API, however the truth has finally surfaced as to what the OP is using to connect with (in an edit and additional comment). I closed the question respectively. – Funk Forty Niner Sep 24 '16 at 14:36
  • Yeah you were right, happy weekend and cheers!!! –  Sep 24 '16 at 16:02