SQL syntax error
I am getting an error message when trying to filter my database records. I'm at a loss ....
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 '= '2012'' at line 1
[ <?php
include "roster.php";
$sql = "SELECT * FROM players";
if (isset ($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['class_filter']);
$sql .= "WHERE class_filter = '{$search_term}'";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<form name="search_form" method="post" action="roster_search.php">
<select name="class_filter" size="1">
<option value="2012">2012</option>
<option value="2011">2011</option>
</select>
<input type="submit" name="search" value="Filter by Class" />
</form>
<table>
<tr>
<th>
Name
</th>
<th>
Number
</th>
<th>
Position
</th>
<th>
Team
</th>
<th>
Class
</th>
</tr>
<?php while ($row = mysql_fetch_array($query)) { ?>.
<tr>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php echo $row['number']; ?>
</td>
<td>
<?php echo $row['position']; ?>
</td>
<td>
<?php echo $row['team']; ?>
</td>
<td>
<?php echo $row['class']; ?>
</td>
</tr>
<?php } ?>
</table>]
Subject
Written By
Posted
SQL syntax error
March 20, 2014 11:00AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.