SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql _fetch_row

    hello, pls can anyone help me fix this error? thanks

    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/autofs/home/s_home1/xyz1/public_html/papers.php on line 46
    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 '' at line 1

    this is line 46
    if(! ($line=mysql_fetch_row($result)))

    and this is line 1
    <?php

    pls tell me when i am going wrong.

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    That means you have a syntax error in your code and it is causing your query to fail. Echo your query out to the screen and look for errors.

  3. #3
    SitePoint Member mjlogan's Avatar
    Join Date
    Apr 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also check that the field names you are using in your query exist in your database.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Helsingborg, Sweden
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also try to use mysql_fetch_array instead of mysql_fetch_row, it's not much slower but it's able to handle multiple results in one row.

  5. #5
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_fetch_array is giving me the same error, and i have checked that field names in my query exist in my database,

    here is my query pls how do i echo it?

    $query="select * from stock where item=$id;";
    $result=mysql_query($query);
    if(! ($line=mysql_fetch_row($result)))
    print mysql_error()

  6. #6
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    <?php echo $query; ?>

  7. #7
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello, thanks for your help i really do appreciate it
    this is what i have done
    $query="select * from stock where item=$id;";
    $result=mysql_query($query);
    if(! ($line=mysql_fetch_row($result)))
    echo $query;
    print mysql_error()

    and this is the result i got
    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/autofs/home/s_home1/xyz1/public_html/papers.phpon line 46
    select * from stock where item=;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 '' at line 1

    and like i mentioned line 1 is <?php

    and line 46 is if(! ($line=mysql_fetch_row($result))

    pls if there is anything i am doing wrong pls let me know
    cheers

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You have to echo the query before the line that is giving you the error. When the error occurs, your program terminates. The idea is to make php output the query to the screen so that you can examine what php is seeing.

    1) You don't include semi-colons in your query string.
    2) You need quotes around your field values if the field is not a numeric type

    Try this:
    Code:
    $query="select * from stock where item='$id' ";

  9. #9
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud
    Hi,

    You have to echo the query before the line that is giving you the error. When the error occurs, your program terminates. The idea is to make php output the query to the screen so that you can examine what php is seeing.

    1) You don't include semi-colons in your query string.
    2) You need quotes around your field values if the field is not a numeric type

    Try this:
    Code:
    $query="select * from stock where item='$id' ";
    The script isn't terminating, it's only giving a warning so execution continues.

    The problem isn't in the fact he's not putting quotes around $id, assuming $id is supposed to be numeric. The problem is coming from the fact that $id has no value. So even if he puts quotes around it, it'd return an empty set which isn't what he wants. He has to figure out why $id is empty.

  10. #10
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script isn't terminating, it's only giving a warning so execution continues.
    Touche. Back at ya:
    The problem isn't in the fact he's not putting quotes around $id
    You can't know that.

    The problem is coming from the fact that $id has no value
    You can query a database all day long with a blank id and not get a warning.

  11. #11
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud
    You can query a database all day long with a blank id and not get a warning.
    You will if the SQL is invalid, which his is. If he used quotes around the $id then his query would look like where item = ''. Assuming each item has an id, it'd return an empty result set.

    But what it's trying to do now is where item = ;.

    mySQL is looking for what item should be equal to, and choking. $id needs to have a value for this to work. He can put quotes around it, and that would get rid of the error, but it would still return no results assuming all his items have ids.

  12. #12
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thks for all your comments i have removed the semi colom and that is what i get, please what do i do now? even changing the value of id from 0 to 1 i still got this same thing. pls tell me what to do .cheers

    select * from stock where item=''

  13. #13
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Looking at that it is obvous your variable $id isn't being set. You need to figure out why.

  14. #14
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i have changed id from 0 to 1 and i still have the same error

  15. #15
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    So where is $id supposed to come from?

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  16. #16
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1)Try this:

    $query="select * from stock where item=0";

    2) Next try this:

    $id = 0;
    $query="select * from stock where item='$id' ";

    3)Post what type your id field is in your table.

  17. #17
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    hi,
    7stud is saying right, use his method.
    if u still get error then try to remove qutoes from the '$id' and try to use $id.
    b'cos any numerical value shuld be without qutoes.


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
  •