Results 1 to 2 of 2

Thread: Php error Sql select

  1. #1
    Join Date
    Mar 2011
    Posts
    2,009
    Thanks
    59
    Thanked 107 Times in 105 Posts
    Blog Entries
    4

    Default Php error Sql select

    For some reason this section of code is causing this error

    ( ! ) Warning: mysql_query() expects parameter 1 to be string, resource given in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\new site\login2\login2.php on line 62
    Call Stack
    # Time Memory Function Location
    1 0.0006 367040 {main}( ) ..\index.php:0
    2 0.0015 397976 include( 'C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\new site\template.php' ) ..\index.php:6
    3 0.0017 441616 page( ) ..\template.php:67
    4 0.0023 466016 include( 'C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\new site\login2\login2.php' ) ..\template.php:30
    5 0.0090 480072 mysql_query ( ) ..\login2.php:62

    ( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\new site\login2\login2.php on line 62
    Call Stack
    # Time Memory Function Location
    1 0.0006 367040 {main}( ) ..\index.php:0
    2 0.0015 397976 include( 'C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\new site\template.php' ) ..\index.php:6
    3 0.0017 441616 page( ) ..\template.php:67
    4 0.0023 466016 include( 'C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\new site\login2\login2.php' ) ..\template.php:30
    5


    PHP Code:
    $bobby mysql_query("SELECT userid FROM online WHERE username = '$username42'")or die(mysql_error());
    if( 
    mysql_num_rowsmysql_query$bobby ) ) != 

    I'm pretty sure that it's in that section


    Here's the full code

    PHP Code:
    <?php 
    require "../database.php";



     
    //if the login form is submitted 
     
    if (isset($_POST['submit'])) {

    ?>
    <?php





     
    // makes sure they filled it in
         
    if(!$_POST['username'] | !$_POST['pass']) {
             die(
    'You did not fill in a required field. <a href="../login">Back</a>');
         }
         
    // checks it against the database

         
    if (!get_magic_quotes_gpc()) {
             
    $_POST['email'] = addslashes($_POST['email']);
         }
         
    $check mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());


     
    //Gives error if user dosen't exist
     
    $check2 mysql_num_rows($check);
     if (
    $check2 == 0) {
             die(
    'I am sorry, the information entered was incorrect. <a href="../login">Back</a>');
                     }
     while(
    $info mysql_fetch_array$check ))     
     {
     
    $_POST['pass'] = stripslashes($_POST['pass']);
         
    $info['password'] = stripslashes($info['password']);
         
    $_POST['pass'] = md5($_POST['pass']);

     
    //gives error if the password is wrong
         
    if ($_POST['pass'] != $info['password']) {
             die(
    'I am sorry, the information entered was incorrect. <a href="../login">Back</a>');
         }
     else 
     { 
     
     
    // if login is ok then we add a cookie 
          
    $_POST['username'] = stripslashes($_POST['username']); 
          
    $hour time() + 3600
     
    setcookie(ID_my_site$_POST['username'], $hour); 
     
    setcookie(Key_my_site$_POST['pass'], $hour);     

    $username42 $info['username'];
    $username44 $info['id'];
    $username43 time();
    $username49 $username43+7200;
    $username47 date("h:i:s"$username49);


    $fraig strtotime('-1day'); 

    $bobby mysql_query("SELECT userid FROM online WHERE username = '$username42'")or die(mysql_error());
    if( 
    mysql_num_rowsmysql_query$bobby ) ) != )

    {
    $sql mysql_query ("INSERT INTO online (id,username,userid,time,time2,ip) VALUES ('0','".$username42."','".$username44."','".$username43."','".$username47."','" $_SERVER['REMOTE_ADDR']."')");
    }




     
     
    //then redirect them to the members area 
    // header("Location: ../echo time"); 
     

     } 
     } 
     else
    {

    }
    Any help would be great!

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    You're running a MySQL query on a MySQL query.

    It's the equivalent of doing this:
    PHP Code:
    $bobby 
    if( 
    mysql_num_rowsmysql_querymysql_query("SELECT userid FROM online WHERE username = '$username42'")or die(mysql_error()) ) ) != 
    ...and obviously, that's not right.

    This should fix it:
    PHP Code:
    $bobby mysql_query("SELECT userid FROM online WHERE username = '$username42'")or die(mysql_error());
    if( 
    mysql_num_rows$bobby ) != 
    - Josh

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
  •