title: mysql_error() expects parameter 1 to be resource, string given
body: <p>I'm working on code for a poll. The admin can create questions and delete them. The user can choose answers from a dropdown menu to answer the questions. This dropdown menu is filled dynamically with a query request.</p>
  
  <p>Now I want the user's name to be inserted in the database when he completes a poll, so he can't do that poll twice. That's what the code here is for.
  This is the query I'm using:</p>
  
  <pre><code>$idfind = "SELECT `id` FROM `Umfragenteilnahme` WHERE `Username` ='$user'";
  $id = mysql_query($idfind) or die (mysql_error());
  if($id) {
      while($rpw = mysql_fetch_assoc($id)) {
          $id = $rpw['id']; // Using $rpw-&gt;id doesnt work
          echo $id; // it gives the right answer and everything works fine
                    //id= 4 for example
      }  
  }
  else {
      echo "Fehler"; // it does not report a fail
  }
  </code></pre>
  
  <p>I know I should use the new <code>mysqli_...</code> tags. The code works absolutely fine and the query gives the right answer and works in MySql database as well.</p>
  
  <p>But every time it gives this error</p>
  
  <blockquote>
    <p>mysql_fetch_assoc() expects parameter 1 to be resource, string given in</p>
  </blockquote>
  
  <p>or for the <code>(mysql_error())</code> this one:</p>
  
  <blockquote>
    <p>mysql_error() expects parameter 1 to be resource, string given in.</p>
  </blockquote>
  
  <p>Everything works fine, but it shows these errors. Why are these errors happening? How can I avoid them?</p>
  
  <p>Edit:
  Now i placed this in the beginning of the code after the first <code>&lt;?php</code> :</p>
  
  <pre><code>set_error_handler ( function($errno, $errstr, $errfile, $errline) {
  if (false!==stripos($errstr, 'mysql')) {
      $file = file($errfile);
      $code = '';
      for($i=max(0, $errline-8); $i&lt;min($errline+8, count($file)); $i++) {
          $code .= sprintf('%4d | %s', $i+1, $file[$i]);
      }
      printf('&lt;fieldset&gt;&lt;legend&gt;%s (%d), %s@%d&lt;/legend&gt;
          &lt;pre&gt;%s&lt;/pre&gt;&lt;/fieldset&gt;',
          htmlspecialchars($errstr), $errno,
          htmlspecialchars($errfile), $errline,
          htmlspecialchars( $code )
      );
  }
  else {
      return false;
  }});
  </code></pre>
  
  <p>The output is this : </p>
  
  <pre><code>Benutzer id: 4
  mysql_fetch_assoc() expects parameter 1 to be resource, string given (2), /censored/censored/www/Website2.0/btn_lehrer.php@36
  
  29 | /* The $user is defined at start of code */
  30 | /* With the next query i get the user-id from this specific user */
  31 | 
  32 | $idfind = "SELECT `id` FROM `Umfragenteilnahme` WHERE `Username`    =   '$user'";
  33 | $id = mysql_query($idfind)or die (mysql_error());
  34 |        if($id){
  35 |            
  36 |                    while($rpw = mysql_fetch_assoc($id)){
  37 |                          $id = $rpw['id'];
  38 |                           echo "Benutzer id: $id ";    //fehler       (Warning: mysql_fetch_assoc() expects parameter 1 to be   resource, string given line 15)                                    
  39 |                        }  
  40 |                      
  41 |                }
  42 |                else{
  43 |                     echo "Fehler bei der Bestimmung der Benutzer id!";
  44 |                    }
  </code></pre>
  
  <p>I hope that you dont mind that it took so long but as i said i completely restructured my code.
  Thanks for all the help so far maybe now someone has the answer to my problem. :)</p>