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



Reply With Quote

Bookmarks