SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with MySQL syntax error "Resource id #7"

    Hi, I am stuck with a SQL syntax error that I can't identify:
    Code:
    Couldn't execute the query query
    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 'Resource id #7' at line 1.
    What is "Resource id #7"?

    I only get the error when I run the query in my PHP script.The same query ran in phpMyadmin doesn't give the error.

    Here's my PHP code;
    PHP Code:
    $date_start_select $_GET['date_start_select'];
    $date_end_select $_GET['date_end_select'];
        
    $query mysql_query("
        SELECT `id`, `date_start`, `date_end`, `title`, `theme`, `body` 
        FROM `moca_daysahead` 
        ORDER BY date_start"
    );

    $result mysql_query($query)
    or die (
    "Couldn't execute the query <i>query</i><br />".mysql_error().".");
    echo 
    "Query: ".$query."<br /><br />";

                
            
    // initialize header and set it to an empty string
            
    $header '';
            
    // mysql_fetch_assoc will return each row from your result set
            // when there are no more results, the while loop ends
            
    while ($row=mysql_fetch_assoc($query))
            {
            
                
    // we only want to print the header if it hasn't been seen in the result yet
                
    if ($header!=$row['date_start'])
                {
                print 
    "<div class=\"header\" style=\"margin-top:20px\"><u>".$row['date_start']."</u></div><br />\n";
                
    // means the current header display is for $row['date_start']
                
    $header $row['date_start'];
                }
            
    $row['h_title'] = utf8_decode($row['title']);
            
    $row['h_theme'] = utf8_decode($row['theme']);
            print 
    "<div style=\"margin-bottom:8px\">";

            print 
    "<b><a href=\"daysahead.php?p=daysahead_edit.php&amp;id=".$row['id']."\">".$row['h_title']."</a></b><br />";

            if (
    $row['theme'])
            {
            print 
    " (".$row['h_theme'].")";
            }
            print 
    "</div>\n";
            } 
    MySQL 5.1.49
    PHP 4.4.9

    Thanks for any help.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by ro1960 View Post
    I only get the error when I run the query in my PHP script.The same query ran in phpMyadmin doesn't give the error.
    this is proof that you are having a php error, not a mysql error

    i don't do php but it looks like you are executing the result of the query

    this executes the query and puts the result into $query --
    Code:
    $query = mysql_query(" 
        SELECT `id`, `date_start`, `date_end`, `title`, `theme`, `body`  
        FROM `moca_daysahead`  
        ORDER BY date_start");
    then you try to execute the result --
    Code:
    $result = mysql_query($query)
    Last edited by r937; Apr 12, 2012 at 04:28. Reason: editing
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    this is proof that you are having a php error, not a mysql error

    i don't do php but it looks like you are executing the result of the query

    this executes the query and puts the result into $query --
    Code:
    $query = mysql_query(" 
        SELECT `id`, `date_start`, `date_end`, `title`, `theme`, `body`  
        FROM `moca_daysahead`  
        ORDER BY date_start");
    then you try to execute the result --
    Code:
    $result = mysql_query($query)

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by abduraooft View Post
    It looks like you have at least one more query in your script and you have supplied the return value of a mysql_query() into it, without fetching any value.
    Indeed, this leftover code seemed to have caused the problem.

    I removed it and it now works.

    Thank you!

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    who is abduraooft?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    who is abduraooft?
    I am not familiar with this word...

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by ro1960 View Post
    I am not familiar with this word...
    read post #4 in this thread
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •