Mysql_fetch_array ---Problem here

Discussion in 'MySQL' started by the_one, Jun 22, 2007.

  1. #1
    I m gettin this error
    when i try to run from a server.
    www.club.phenyu.com
    Help needed here as i have more problem i wanna tackle 1 by one

    thank you
     
    the_one, Jun 22, 2007 IP
  2. mickmel

    mickmel Peon

    Messages:
    384
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That means it's an invalid query. Look closer at this:

    SELECT id FROM $tab[user] WHERE code='$pkuser';

    The error is something in there. Is "id" a valid field? If so, maybe try changing $tab[user] to the static name of your db to see if the error is there.
     
    mickmel, Jun 22, 2007 IP
  3. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    take the mysql_query functions out of the mysql_fetch_array functions, and add this after mysql_query(....):
     or die(mysql_error());
    PHP:
    so instead of:
    mysql_fetch_array(mysql_query("SELECT id FROM $tab[user] WHERE code='$pkuser';"));
    PHP:
    use this:
    $res = mysql_query("SELECT id FROM $tab[user] WHERE code='$pkuser'") or die(mysql_error());
    $id = mysql_fetch_array($res);
    PHP:
    The reason why you get this error is because the query probably has an error in it. Try wrapping the tablename in { }, that way php will parse it as a variable. I think at the moment php parses it as {$tab}[user] and not {$tab[user]}.
    mysql_query("SELECT id FROM {$tab[user]} WHERE code='$pkuser'") or die(mysql_error());
    PHP:
     
    UnrealEd, Jun 22, 2007 IP
  4. PenSniffer

    PenSniffer Guest

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    the $tab[user] won't work as you expect, you didn't show where this was set and make sure it is mysql_real_escape_string, also its most often easier to read/maintain code written with mysql_fetch_assoc
     
    PenSniffer, Jun 22, 2007 IP
  5. the_one

    the_one Banned

    Messages:
    344
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanx man really appreciated it i will work on it again .
     
    the_one, Jun 22, 2007 IP
  6. the_one

    the_one Banned

    Messages:
    344
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry man i add you php code it does works
    it says club.user doesnt exist.:(
     
    the_one, Jun 22, 2007 IP
  7. the_one

    the_one Banned

    Messages:
    344
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    well can you suggest me what should be done . as i am confused . :confused:
     
    the_one, Jun 22, 2007 IP
  8. CriminalOrigins

    CriminalOrigins Peon

    Messages:
    276
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Maybe try $tab['user'] instead. Sometimes the ' ' are necessary :)
     
    CriminalOrigins, Jun 22, 2007 IP
  9. the_one

    the_one Banned

    Messages:
    344
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thanx man but it doesnt worked.:)
     
    the_one, Jun 22, 2007 IP
  10. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #10
    place it outside the double quotes, or use sprintf:
    $query = "SELECT id FROM " . $tab['user'] . " WHERE code='" . $pkuser ."'";
    PHP:
    or:
    $query = sprintf("SELECT id FROM %s WHERE code='%s'", $tab['user'], $pkuser);
    PHP:
    i think it should work now
     
    UnrealEd, Jun 23, 2007 IP
  11. the_one

    the_one Banned

    Messages:
    344
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #11
    oh now its ok i just added @mysql
    i used@
    thats it thank you my frnd.

    Closed Topic
     
    the_one, Jun 24, 2007 IP
  12. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #12
    @ doesn't solve the problem, it just silences the error. If that's all you changed, your query isn't working, you just don't see an error.
     
    UnrealEd, Jun 24, 2007 IP
  13. the_one

    the_one Banned

    Messages:
    344
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #13
    ok . this mean when i put @ it just silences the script.

    thats why i was wondering as now i cant register it damn:mad:

    anyone please help me again as i am learning on my own:cool:
     
    the_one, Jun 27, 2007 IP
  14. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #14
    can you post the code you're using atm, and the error you get when you remove the @ signes?
    i don't know if the error_reporting is set to maximum, but if not, place these lines on top of your code:
    error_reporting ( E_ALL );
    ini_set ( 'display_errors', '1' );
    PHP:
    If you have an error in your php script, the above code will display it in the window.
     
    UnrealEd, Jun 28, 2007 IP
  15. rajeev_seo

    rajeev_seo Peon

    Messages:
    211
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    its means
    problem in your query first check your query and add
    error_reporting ( E_ALL );
    ini_set ( 'display_errors', '1' ); that code on the top of lthe page for know the exit problem
    its function return error repoeting
     
    rajeev_seo, Apr 23, 2011 IP