Results 1 to 4 of 4

Thread: error in your SQL syntax; check the manual that corresponds to your MySQL server ver

  1. #1
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default error in your SQL syntax; check the manual that corresponds to your MySQL server ver

    Hello,

    I’m new to mysql and I get this error message when I try to get a result from FromList.php3 page to listResults.php3 page:

    http://…/listResults.php3?ticket_id=23834

    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 'ORDER BY created_date' at line 4

    Here it’s code for FromList.php3
    Code:
    <html>
    <head><title>View tickets records</title>
    
    <?
    //include stylesheet for formatting
    include("stylesheet.php3");
    ?>
    
    </head>
    <body>
    
    <?
    // script to display all the Ticket_ids in the TICKET table
    
    // connection information
    $hostName = "myhost";
    $userName = "myuser";
    $password = "mypassword";
    $dbName = "mydb";
    
    // make connection to database 
    mysql_connect($hostName, $userName, $password) or die("Unable to connect
    to host $hostName");
    
    mysql_select_db($dbName) or die("Unable to select database $dbName");
    
    // Select all the fields in all the records of the TICKET table 
    $query = "SELECT * 
              FROM TICKET_TABLE
              ORDER BY ticket_id, created_date";
    $result = mysql_query($query);
    
    // Determine the number of tickets 
    $number = mysql_numrows($result);
    
    /* Print the tickets 
       make names hyperlinks to 
       lisresults.php3?Ticket_id=$ ticket_id */
    
    print "<table cellpadding=5>
          <tr bgcolor=\"lightgrey\">
           <td>
             <b>Select one of the following:</b>
           </td>
          </tr>
        </table>
        <ul>";
    for($i=0; $i<$number; $i++) {
         $ticket_id = mysql_result($result,$i,"ticket_id");
         $created_date = mysql_result($result,$i,"created_date");
         $ticket_status = mysql_result($result,$i, "ticket_status");
         print "<li>
         <a href=\"listResults.php3? ticket_id = $ticket_id\">
         $ticket_id</a>
         </li>";
    }
    print "</ul>";
    
    // Close the database connection
    mysql_close();
    ?>
    
    </body>
    </html>
    Here it’s code for listResults.php3
    
    <html>
    <head><title>CRDs</title>
    
    <?
    //include stylesheet for formatting
    include("stylesheet.php3");
    ?>
    
    </head>
    <body>
    
    <?
    // script to display CRDs
    
    // connection information
    $hostName = "myhost";
    $userName = "myuser";
    $password = "mypassword";
    $dbName = "mydb";
    
    // make connection to database
    mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
    
    mysql_select_db($dbName) or die("Unable to select database $dbName");
    
    // Select the fields from the appropriate tables
    
    $query =
            "SELECT ticket_id, created_date, ticket_status
    		FROM TICKET_TABLE
    		WHERE ticket_id = $ticket_id
    		ORDER BY created_date";
    
    $result = mysql_query($query) or die(mysql_error());
    
    // Determine the number of records returned 
    $number = mysql_num_rows($result);
    
    // Print the relevant information
    
    print "<h2>There are $number records in the ticket database:</h2>";
    print "<table cellpadding=5>";
    print "    <tr bgcolor=black>
          <td><font color=white><b>TICKET_ID</b></font></td>
          <td><font color=white><b>CREATED_DATE</b></font></td>
          <td><font color=white><b>TICKET_STATUS</b></font></td></tr>";
    for($i=0; $i<$number;  $i++) {
        $ticket_id = mysql_result($result, $i, "ticket_id");
        $created_date = mysql_result($result, $i, "created_date");
        $ticket_status = mysql_result($result,$i,"ticket_status");
        /* print even-numbered rows with a grey background, 
               odd-numbered with a white background */
            if ($i%2 == 0) {
            print "<tr bgcolor=lightgrey>";
            } else {
            print "<tr>";
            }
        print "<td>$ticket_id</td>
        <td>$created_date</td>
        <td>$crd_sttus</td></tr>";        
    }
    print "</table>";
    
    // Close the database connection
    mysql_close();
    ?>
    
    </body>
    </html>
    Edit: Wrapped the code in [code][/code] tags
    Last edited by tech_support; 01-08-2008 at 12:48 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have PHP Version 4.4.0 and Apache 2.0 Handler if that helps.

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Try changing the $query string to this:
    PHP Code:
    $query "SELECT `ticket_id`, `created_date`, `ticket_status` FROM `TICKET_TABLE` WHERE `ticket_id` = '$ticket_id' ORDER BY `created_date`"
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    I forgot to define ticket_id in my second/results page, I just added the line:

    $ticket_ = $_GET['ticket_id'];

    This did the trick, thanks...

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
  •