hi

I've seen a few of these posts but none have solved my issue. I am an extreme newbie, if someone could tell me why I get this error (and what it means) I would be grateful.

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, resource given in C:\wamp\www\Ali elsharif\combination\login.php on line 17

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, resource given in C:\wamp\www\Ali elsharif\combination\login.php on line 18

this is my code
?php
require_once('easyaccess.php');

// Start the session
session_start();

// Clear the error message
$error_msg = "";

// If the user isn't logged in, try to log them in
if (!isset($SESSION['id'])) {
if (isset($
POST['submit'])) {
// Connect to the database
$dbc = mysql_connect(HOST, USER, PASSWORD, D😎;

  // Grab the user login data
  $user_username = mysqli_real_escape_string($dbc, trim($_POST['user_id']));
  $user_password = mysqli_real_escape_string($dbc, trim($_POST['password']));

    if(!empty($user_username) && !empty($user_password)) {
    // Look up the username and password in the database
     $query = "Select id,user_id FROM users WHERE user_id ={$_POST['user_username']} AND password ={$_POST['user_password']}";
     $data  = mysql_query($dbc, $query);

    if (mysql_num_rows($data) == 1) {
      // The login is okay
      $row = mysql_fetch_array($data);
      $_SESSION['id'] = $row['id'];
      $_SESSION['user_id'] = $row['user_id'];
      setcookie('id', $row['id'], time() + (60 * 60 * 24 * 30));    // expires in 30 days
      setcookie('user_id', $row['user_id'], time() + (60 * 60 * 24 * 30));  // expires in 30 days
      $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.html';
      header('Location: ' . $home_url);
    }
    else {
      // The username/password are not correct
      $error_msg = 'Sorry, you must enter a valid username and password to login.';
    }
  }
  else {
    // The username/password weren't entered so set an error message
    $error_msg = 'Sorry, you must enter your username and password to log in.';
  }
}

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Drugs World - Login</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
<div id="header-wrapper">
<div id="header">
<div id="logo">
<h1>Drugs-World</h1>
<p>All drugs types, benefits-unbenefits and detials.</p>
</div>
<div id="menu">
<ul>
<li class="current_page_item"><a href="index.html">Home</a></li>
<li><a href="login.php">Login</a></li>
<li><a href="signup.php">Sign up</a></li>
<li><a href="edit.php">Edit</a></li>
<li><a href="logout.php">Logout</a></li></ul>
</div>
</div>
</div>
<!-- end #header -->
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<div id="content">
<div class="post">
<?php
// If the session is empty, show error message and the log-in form.
if (empty($_SESSION['user_id'])) {
echo '<p class="error">' . $error_msg . '</p>';
?>
<h2 class="title"><a href="#">Login in Entry:</a></h2>
<div class="entry">
<p><b>Enter your username and password:</b></p>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<fieldset>
<legend>Log In</legend>
<label for="username">Username:</label>
<input type="text" name="user_id" value="<?php if (!empty($user_username) && isset($submit)) { echo $user_username; } ?>" /><br />
<label for="password">Password:</label>
<input type="password" name="password" />
</fieldset>
<input type="submit" value="Log In" name="submit" />
</form>

<?php
}
else {
// Confirm the successful log-in
echo('<p>Hello, You are already logged in as [ ' . $_SESSION['user_id'] . ' ] ! .</p>');
}
?>
</div>
<div class="byline">
<p class="links">&nbsp;</p>
</div>
</div>
</div>
<!-- end #content -->
<div id="sidebar">
<ul>
<li>
<div id="search" >

    When posting code in the forums, please use the forum markup tags described in the FAQs to mark up your code.

    You're using [man]mysql_connect[/man] instead of [man]mysqli_connect[/man].
    And a little later on, you're using [man]mysql_query[/man] instead of [man]mysqli_query[/man]. And [man]mysql_fetch_array[/man] instead of [man]mysqli_fetch_array[/man].

      I alredy changed all to mysql because mysqli does not work but i still got these 2 warnings

      Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in C:\wamp\www\Ali elsharif\combination\login.php on line 17

      Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in C:\wamp\www\Ali elsharif\combination\login.php on line 18

        Showing you, right in the error message, that you did not change them all to mysql, namely the 2 calls to mysqli_real_escape_string. In reality you should not be changing from mysqli to mysql but rather the other way around.

          In the mysql version of that function (versus the mysqli version), the mysql connection resource argument is (a) optional and (b) comes 2nd in the parameter list (not first).

            Write a Reply...