I keep getting the following error:
Error performing 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 'WHERE (runtotals.id = '1)' at line 1
I can't find what the problem is. Here is my code for the php page:
Any ideas?? Thanks in advance!Code:<html> <head> <title>Update Monthly Incident Totals</title> </head> <body> <?php if (!$_REQUEST['Submit']) { html_form(); } elseif ($_REQUEST['Submit'] == "ViewTotals") { select_month(); } elseif ($_REQUEST['Submit'] == "Edit") { get_data(); } elseif ($_REQUEST['Submit'] == "Update") { update_total(); } function my_conn() { /* set's the variables for MySQL connection */ $server = "localhost"; $username = "myusername"; $password = "mypass"; /* Connects to the MySQL server */ $link = @mysql_connect ($server, $username, $password) or die (mysql_error()); /* Defines the Active Database for the Connection */ if (!@mysql_select_db("innovati_firedept", $link)) { echo "<p>There has been an error. This is the error message:</p>"; echo "<p><strong>" . mysql_error() . "</strong></p>"; echo "Please Contact Your Systems Administrator with the details"; } return $link; } function html_form() { $conn = my_conn(); $SQL = "SELECT DISTINCT runtotals.month FROM runtotals;"; $result = mysql_query($SQL, $conn); if (!$result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } ?> <p>Please select the month that you would like to update.</p> <form name="runtotals" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>"> Month: <select name="month"> <? while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo("<option value=\"" . $row["month"] . "\">" . $row["month"] . "</option>\n"); } ?> </select> <input type="submit" name="Submit" value="ViewTotals" /> </form> <? /* Closes Connection to the MySQL server */ mysql_close ($conn); } function select_month() { ?> <h4>Current Totals</h4> <? $conn = my_conn(); /* Sets the SQL Query */ $sql = "SELECT * FROM runtotals"; $sql .= " WHERE (runtotals.month = '{$_POST['month']}')"; /* Passes a Query to the Active Database */ $result = mysql_query($sql, $conn); if (!$result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } /* Starts the table and creates headings */ ?> <table> <tr> <td><strong>Month</strong></td> <td><strong>Total</strong></td> <td></td> </tr> <? /* Retrieves the rows from the query result set and puts them into a HTML table row */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo("<tr>\n<td>" . $row["month"] . "</td>"); echo("<td>" . $row["total"] . "</td>"); echo("<td><a href=\"" . $_SERVER['PHP_SELF'] . "?id=" .$row['id'] . "&Submit=Edit\">Edit</a></td></tr>\n\n"); } /* Closes the table */ ?> </table> <? /* Closes Connection to the MySQL server */ mysql_close ($conn); html_form(); } function get_data() { /* Calls our connection function */ $conn = my_conn(); /* Defines query */ $sql = "SELECT * FROM runtotals WHERE (runtotals.id = " . $_REQUEST['id'] . ")"; /* Passes query to database */ $result = mysql_query($sql, $conn); if (!$result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } /* creates our row array with an if statement to report errors */ if ($row = @mysql_fetch_array($result, MYSQL_ASSOC)) { /* prints out the artist and title */ print "<h4>$row[month] - $row[total]</h4>"; /* prints out our HTML form '\"' */ print "<form name=\"CDs\" method=\"post\" action=\"$_SERVER[PHP_SELF]\">"; /* Prints out hidden releaseID - we don't put this in the HTML form so that the uer cannot edit the Key value in error */ //print "<input type=\"text\" name=\"id\" value=\"$row[id]\">"; /* prints out our HTML table and fields 'escaping' any double quotes '\"' */ print "<table width=\"600\"> <tr> <td width=\"100\"><strong>New Total:</strong></td> <td width=\"150\"><input type=\"text\" name=\"total\" value=\"$row[total]\"></td> <td rowspan=\"5\" valign=\"top\"><input type=\"submit\" name=\"Submit\" value=\"Update\"> </td> </tr> </table> </form>"; /* Counts the number of rows (therefore copies) */ //$count = mysql_num_rows($result_count); //if ($count != 1) { //print "<p>There are $count copies of this CD</p>"; //} else { //print "<p>There is $count copy of this CD</p>"; //} //} else { // echo("There has been an error" . mysql_error()); } /* closes connection */ mysql_close ($conn); } function update_total() { /* Calls our connection function */ $conn = my_conn(); /* Defines query */ $sql_update = "UPDATE runtotals SET "; $sql_update .= "runtotals.month = '" . $_REQUEST['month'] . "', "; $sql_update .= "runtotals.total = '" . $_REQUEST['total'] . "', "; $sql_update .= "WHERE (runtotals.id = '" . $_REQUEST['id'] . ")"; /* Passes query to database */ $result = mysql_query($sql_update, $conn); if (!$result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } /* Prints succes message */ print "<p> Successfully Updated</p>"; /* closes connection */ mysql_close ($conn); /* Calls get_data() function */ get_data(); } ?> </body> </html>






Bookmarks