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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    Hi,

    I am getting this error on my wepage

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    This is my code:

    <?php
    require_once("connect.php");

    if(isset($_GET['userSearch'])) {
    $srch=$_GET['userSearch'];
    $allMov = "SELECT * FROM tbl_handbags WHERE handbags_name LIKE '%".
    $srch."%' ORDER BY handbags_name";
    } else if (isset($_GET['nav'])) {
    $select=$_GET['nav'];
    $allMov = "SELECT * FROM tbl_handbags, tbl_cat, tbl_l_hc WHERE tbl_handbags.handbags_id =tbl_l_hc.handbags_id AND tbl_cat.cat_id=tbl_l_hc.cat_id AND tbl_cat.cat_name = '".$select."' ORDER BY tbl_handbags.handbags_id ASC";

    }
    else{
    $allMov = "SELECT * FROM tbl_handbags ORDER BY handbags_id ASC";

    }

    $movResults = mysql_query($allMov);

    ?>

    And this is the line with the coding error:

    while($row = mysql_fetch_array($movResults)){


    It worked the entire time I was using LOCALHOST and building the site but as soon as I went live it fell apart.

    Can someone please help me out??

    Thank you

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Welcome to the forums. For the note, please wrap code in the appropriate code or PHP tags. It makes it much easier to read and help.

    In short, that error means the query failed. Why it failed is another question as you don't have any error checking. Addin mysql_error (PHP: mysql_error - Manual) to help there. But yah, that's the core of your problem. Maybe your local database and production databases are different? I assume when you say you were using localhost it was working you mean a separate machine then your production environment. Note that saying you were using localhost doesn't say anything. localhost is the commonly used alias to mean the host on my machine. Every server/system I have has a localhost.

    I'd also recommend sanitizing your inputs. If that's your live launch, it would take one command to bring down your database. Use mysqli or PDO; they're easier to manage, and at least PDO has good error wrappers (I use PDO, so I can't say much about mysqli). Unsanitized inputs is a HUGE database no no.


  •  

    Tags for this Thread

    Posting Permissions

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