title: Unable to execute MYSQL query inside a PHP function
body: <p>PHP:</p>
  
  <pre><code>function generate_uid() {  
    $uid = mt_rand();  
  
    $sql = "SELECT user_id  
              FROM user_registration";  
  
    if (!mysql_query($sql,$con)) {  
      die('Error: ' . mysql_error());  
    }  
  
    $result = mysql_query($sql);  
    $availability = TRUE;  
  
    while($row = mysql_fetch_array($result)) {  
      if($row['user_id'] == $uid) {  
        $availability = FALSE; 
      }  
    }
  
    if($availability == FALSE) {
      generate_uid();
    }  
  }  
  </code></pre>
  
  <h2>The error</h2>
  
  <blockquote>
    <p>Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in E:\Web Design EC\register2.php on line 8
    Error: </p>
  </blockquote>
  
  <p>But when i execute this function as normal php there is no error and the $uid is generated. What maybe the problem??</p>