mysql query problem. Might be the use of arrays. Helpz

Discussion in 'PHP' started by dmanto2two, Jan 16, 2010.

  1. #1
    My error is
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com AND active = 1' at line 1
    while using this query
    $q = mysql_query("SELECT friend_email FROM friend WHERE user_email = $user_id AND active = $woo ") or die(mysql_error());

    the information that come from it is passed into an array.

    also I tried putting the variables in '". ."'
    i also tried remaking the table with different cell names
    btw the table in
    user_email varchar(50)
    friend_email varchar(50)
    active tinyint
    anyway for now i give. i played around with it for almost 5 hours now and i need help with this query even more than i need sleep.:)
     
    dmanto2two, Jan 16, 2010 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    You must enclose varchar values with single quotes.

    $q = mysql_query("SELECT friend_email FROM friend WHERE user_email = '$user_id' 
    AND active = $woo ") or die(mysql_error());
    Code (markup):
     
    mwasif, Jan 17, 2010 IP
  3. dmanto2two

    dmanto2two Peon

    Messages:
    56
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wow your a hero. that fixed the mysql error.
    Unfortunatley i now have an array problem now.
    the error is
    Warning: array_push() expects parameter 1 to be array, null given in C:\xampp\htdocs\member.php on line 45

    Warning: array_push() expects parameter 1 to be array, null given in C:\xampp\htdocs\member.php on line 45

    Warning: array_push() expects parameter 1 to be array, null given in C:\xampp\htdocs\member.php on line 50

    Warning: array_push() expects parameter 1 to be array, null given in C:\xampp\htdocs\member.php on line 50

    Warning: array_push() expects parameter 1 to be array, null given in C:\xampp\htdocs\member.php on line 50

    the code giving me problems is
    while($r = mysql_fetch_array($q)){
    array_push($arrFriendList, $r['friend_email']);
    }

    i defined array as $arrFriendlist = array();
    anyway sorry to drag this problem out
    i'm thinking i may have to do this with inegers. maybe assign my user uniqid's?
     
    dmanto2two, Jan 17, 2010 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    Did you define array $arrFriendlist before using it?
     
    mwasif, Jan 17, 2010 IP
  5. Steve136

    Steve136 Peon

    Messages:
    240
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There shouldn't be any need to use array_push(). Try this, it does the same job.

    
    $arrFriendList = array();
    while($r = mysql_fetch_array($q)){
        $arrFriendList[] = $r['friend_email'];
    }
    
    PHP:
    As stated on PHP.net
    Also take care when naming variables, $arrFriendList is different to $arrFriendlist you could of defied $arrFriendlist as an array but be using the capital L somewhere else in the code.

    Regards,
    Steve
     
    Last edited: Jan 17, 2010
    Steve136, Jan 17, 2010 IP
  6. dmanto2two

    dmanto2two Peon

    Messages:
    56
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    steve you are amazing. it not only works, but faster. so very kool.
    thanks to steve and mwasif. you guys saved me hours of bashing my head against a wall.
    I declare this one fixed!
     
    dmanto2two, Jan 17, 2010 IP