SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting frustrated with simple PHP/MySQL problem

    For some reason a simple database connection script that was working fine is now throwing up the following error message:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bounce6/public_html/inf.php on line 45
    The code is as follows:

    PHP Code:
    include '../db_vars.php';

        
    $connect mysql_connect($dbhost$dbuser$dbpasswd) or die (mysql_error());
        
    mysql_select_db($dbname);

    echo 
    $_GET['lodgeindex'];

    if (isset(
    $_GET['choice'])){

    $choice=$_GET['choice'];

    $recent_sql "SELECT id, title, type, price, description, hire, age, adults, requirements, overnight, picture, dim, gallerypics FROM range WHERE type='$choice'ORDER BY price ASC";

    $result=mysql_query($recent_sql);
      while (
    $recent mysql_fetch_array($result))
        {
    [
    I].... print out results[/I]

    Line 45 is the beginning of the while statement.

    Can someone tell me if there's any problem with that PHP code, or if there's any other reason why these errors may now have suddenly started cropping up.

    From an SQL point of view, I've checked that the name of the table is correct and that all of the table fields are valid ... and it's still not working. Is there something else I should be checking??

    Thanks very much for your help ...

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your SQL query is invalid, which is why there's no result resource to fetch rows from.

    Code:
     type='$choice'ORDER
    You lost your space between that field and the ORDER BY clause.
    Last edited by Dan Grossman; Feb 19, 2010 at 21:47.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    it's gotta be something else, dan -- mysql is smart enough to parse the sql without that particular space being there
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change this
    PHP Code:
    $result=mysql_query($recent_sql); 
    to
    PHP Code:
    $result=mysql_query($recent_sql) or die(mysql_error()); 
    If the query fails, which it is, you'll see an error message describing the problem. You also need to look into sql injection, because you are opening up security holes in your current code. Depending what those variables are, they could even be the cause of your problem.
    Adrian Schneider - Web Developer


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
  •