title: change password code error
body: <p>I've created a code to change a password. Now it seem contain an error. When I fill in the form to change password, and click save the error message:</p>
  
  <blockquote>
    <p>Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in C:\Program Files\xampp\htdocs\e-Complaint(FYP)\userChangePass.php on line 103</p>
    
    <p>Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in C:\Program Files\xampp\htdocs\e-Complaint(FYP)\userChangePass.php on line 103</p>
  </blockquote>
  
  <p>I really don’t know what the error message means. Please guys. Help me fix it.</p>
  
  <p>Here's is the code:</p>
  
  <pre><code>&lt;?php session_start(); ?&gt;
  &lt;?php # change password.php
  
  //set the page title and include the html header.
  $page_title = 'Change Your Password';
  //include('templates/header.inc');
  
  if(isset($_POST['submit'])){//handle the form
      require_once('connectioncomplaint.php');//connect to the db.
      //include "connectioncomplaint.php";
  
      //create a function for escaping the data.
      function escape_data($data){
          global $dbc;//need the connection.
          if(ini_get('magic_quotes_gpc')){
              $data=stripslashes($data);
          }
          return mysql_real_escape_string($data, $dbc);
      }//end function
  
      $message=NULL;//create the empty new variable.
  
      //check for a username
      if(empty($_POST['userid'])){
          $u=FALSE;
          $message .='&lt;p&gt; You forgot enter your userid!&lt;/p&gt;';
      }else{
          $u=escape_data($_POST['userid']);
      }
  
      //check for existing password
      if(empty($_POST['password'])){
          $p=FALSE;
          $message .='&lt;p&gt;You forgot to enter your existing password!&lt;/p&gt;';
      }else{
          $p=escape_data($_POST['password']);
      }
  
      //check for a password and match againts the comfirmed password.
      if(empty($_POST['password1'])) {
          $np=FALSE;
          $message .='&lt;p&gt; you forgot to enter your new password!&lt;/p&gt;';
      }else{
          if($_POST['password1'] == $_POST['password2']){
          $np=escape_data($_POST['password1']);
      }else{
          $np=FALSE;
          $message .='&lt;p&gt; your new password did not match the confirmed new password!&lt;/p&gt;';
      }
  }
  
  if($u &amp;&amp; $p &amp;&amp; $np){//if everything's ok.
  
      $query="SELECT userid FROM access WHERE (userid='$u' AND password=PASSWORD('$p'))";
      $result=@mysql_query($query);
      $num=mysql_num_rows($result);
      if($num == 1){
          $row=mysql_fetch_array($result, MYSQL_NUM);
  
          //make the query
          $query="UPDATE access SET password=PASSWORD('$np') WHERE userid=$row[0]";
          $result=@mysql_query($query);//run the query.
          if(mysql_affected_rows() == 1) {//if it run ok.
  
              //send an email,if desired.
              echo '&lt;p&gt;&lt;b&gt;your password has been changed.&lt;/b&gt;&lt;/p&gt;';
              include('templates/footer.inc');//include the HTML footer.
              exit();//quit the script.
  
          }else{//if it did not run OK.
              $message= '&lt;p&gt;Your password could not be change due to a system error.We apolpgize for any inconvenience.&lt;/p&gt;&lt;p&gt;' .mysql_error() .'&lt;/p&gt;';
              }
          }else{
              $message= '&lt;p&gt; Your username and password do not match our records.&lt;/p&gt;';
          }
          mysql_close();//close the database connection.
  
      }else{
          $message .='&lt;p&gt;Please try again.&lt;/p&gt;';
      }
  }//end oh=f the submit conditional.
  
  //print the error message if there is one.
  if(isset($message)){
      echo'&lt;font color="red"&gt;' , $message, '&lt;/font&gt;';
  }
  ?&gt;
  
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
  
  
  
  
  
  &lt;body&gt;
  &lt;script language="JavaScript1.2"&gt;mmLoadMenus();&lt;/script&gt;
  &lt;table width="604" height="599" border="0" align="center" cellpadding="0" cellspacing="0"&gt;
    &lt;tr&gt;
      &lt;td height="130" colspan="7"&gt;&lt;img src="images/banner(E-Complaint)-.jpg" width="759" height="130" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td width="100" height="30" bgcolor="#ABD519"&gt;&lt;/td&gt;
      &lt;td width="100" bgcolor="#ABD519"&gt;&lt;/td&gt;
      &lt;td width="100" bgcolor="#ABD519"&gt;&lt;/td&gt;
      &lt;td width="100" bgcolor="#ABD519"&gt;&lt;/td&gt;
      &lt;td width="100" bgcolor="#ABD519"&gt;&lt;/td&gt;
      &lt;td width="160" bgcolor="#ABD519"&gt;
      &lt;?php include "header.php"; ?&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan="7" bgcolor="#FFFFFF"&gt;
  
  &lt;fieldset&gt;&lt;legend&gt; Enter your information in the form below:&lt;/legend&gt;
  
  &lt;p&gt;&lt;b&gt;User ID:&lt;/b&gt; &lt;input type="text" name="username" size="10" maxlength="20" value="&lt;?php if(isset($_POST['userid'])) echo $_POST['userid']; ?&gt;" /&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;b&gt;Current Password:&lt;/b&gt; &lt;input type="password" name="password" size="20" maxlength="20" /&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;b&gt;New Password:&lt;/b&gt; &lt;input type="password" name="password1" size="20" maxlength="20" /&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;b&gt;Confirm New Password:&lt;/b&gt; &lt;input type="password" name="password2" size="20" maxlength="20" /&gt;&lt;/p&gt;
  &lt;/fieldset&gt;
  
  &lt;div align="center"&gt; &lt;input type="submit" name="submit" value="Change My Password" /&gt;&lt;/div&gt;
  
  &lt;/form&gt;&lt;!--End Form--&gt;
  
      &lt;/td&gt;
  
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>