PDA

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



tepaboy
01-07-2008, 04:49 PM
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


<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>

Wrapped the code in
tags

tepaboy
01-07-2008, 04:52 PM
I have PHP Version 4.4.0 and Apache 2.0 Handler if that helps.

tech_support
01-08-2008, 12:46 AM
Try changing the $query string to this:


$query = "SELECT `ticket_id`, `created_date`, `ticket_status` FROM `TICKET_TABLE` WHERE `ticket_id` = '$ticket_id' ORDER BY `created_date`";

tepaboy
01-08-2008, 12:49 PM
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...