SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error with mysqli_real_escape_string

    Hi,

    I am running a php script in XAMPP (see below) and I am constantly getting this error:

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\funstuff\signin.php on line 7

    <?php session_start();
    include('include/db.php');
    //check for session

    if(isset($_POST['submit'])){
    $dbc=mysql_connect(DB_HOST,DB_USER,DB_PW,DB_NAME);
    $username =mysqli_real_escape_string($dbc,trim($_POST['username']));
    $password=mysqli_real_escape_string($dbc,trim($_POST['password']));
    //check to see if user is signed in
    $query="SELECT user_id,user_name FROM users WHERE user_name='$username' AND user_password=SHA('$password')";
    $data=mysqli_query($dbc,$query);
    if(mysqli_num_rows($data)==1){
    $data2=mysql_fetch_array($data);
    $_SESSION['user_id']=$data2['user_id'];
    $_SESSION['username']=$data2['user_name'];

    echo('success');
    }
    else{echo'no match';}

    }




    ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,411
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    How about using mysqli_connect?

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have mixed up two libraries together related to mysql mysql and mysqli. So either you connect with mysqli_connect and use all the functions as you have used or connect to mysql server with mysql_connect and use all the functions of mysql_*.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as guido2004 said, you need to use msqli_connect() if you are going to use the functions in PHP's mysqli extension to "talk" to your database.

  5. #5
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Yeah, you need to be using mysqli_connect instead of mysql_connect!

    :P


Bookmarks

Posting Permissions

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