Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    valid MySQL result resource Error, Need Help

    Code:
    <?
    
    $con1 = mysql_connect("localhost","uname","pass");
    
    if (!$con1)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    if ($con1)
      {
       echo "<h5>Connection Success!</h5>";
      }
    
    mysql_select_db("jrmsport_verify", $con1);
    
    
    $sql="SELECT * FROM Verify";
    
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
    
      {
      echo $row['Item'];
      }
    
    mysql_close($con1); 
    
    ?>
    Would someone be able to tell me why I'm getting the error

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/jrmsport/public_html/verifyTest.php on line 27

    I get a successful connection to the sql server, my database is called jrmsport_verify and my table is called Verify.
    Just doesn't make sense to me, as this exact code has worked for me in the past with different db connections. Thanks for the help.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try
    PHP Code:
    $result mysql_query($sql) or die(mysql_error()); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Is your table Verify or verify? Is your column named Item or item?

    *nix is case sensitive, windows is not.

  • #4
    New Coder
    Join Date
    Jun 2010
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post
    Do this to check result of sql query:
    Quote Originally Posted by abduraooft View Post
    Try
    PHP Code:
    $result mysql_query($sql) or die(mysql_error()); 
    and be careful and check for this
    Quote Originally Posted by guelphdad View Post
    Is your table Verify or verify? Is your column named Item or item?

    *nix is case sensitive, windows is not.
    also you can try
    Code:
    sql="SELECT * FROM `Verify`";
    , because i am not quite sure, but `Verify` can be reserved word.

  • #5
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    $result = mysql_query($sql) or die(mysql_error());
    This results in:

    "No database selected"

    The cases of my table and all columns match up.

    Any ideas?

    EDIT: After adding the single quotes around Verify as saviola suggested, I now get this error:

    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 ''Verify'' at line 1
    Last edited by noclist; 06-13-2010 at 07:04 PM.

  • #6
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    Verify isn't a reserved word and you need to use backticks not single quotes around the table name. Backtick is the button above your tab button. The problem I believe is it is not selecting the database at mysql_select_db("jrmsport_verify", $con1) and therefore the mysql_query function needs a link to connect to resulting in an invalid resource on the fetch statement.

    Try...
    PHP Code:
    mysql_select_db("jrmsport_verify"$con1) or die(mysql_error()); 
    The user may not have access to your database or it may be misspelled.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •