I have a real 'newbie' question but have been unable to find a solution for it after extensive searches in various manuals. I am trying to do a very simple 'SELECT' query in a MYSQL database using a form to provide a 'filter' for the query. Here is the script I'm using for the form:
<?
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">
<P ALIGN=CENTER><br />
<b>Person for whom you want a Report</b> -- <input type="text" name="name"><br /><br />
<P ALIGN=CENTER><br /><input type="submit" value="Get Report!">
</form>';
}
?>
//Using the input from this form, I have then constructed the following query to get the report:
<?
$sql = 'SELECT * FROM news WHERE name=($_POST['name'])';
$res = mysql_query($sql);
while ($article = mysql_fetch_array($res)) {
echo '<TR><TD WIDTH="9%" VALIGN=TOP><P>'.$article["period"].'</TD><TD WIDTH="9%" VALIGN=TOP><P>'.$article["posted"].'</TD><TD WIDTH="9%" 144VALIGN=TOP><P>'.$article["church"].'</TD><TD WIDTH="9%" VALIGN=TOP><P>'.$article["reporter"].'</TD><TD WIDTH="9%" VALIGN=TOP><P><CENTER>'.$article["baptisms"].'</TD><TD WIDTH="9%" VALIGN=TOP><P><CENTER>'.$article["worship"].'</TD><TD WIDTH="9%" VALIGN=TOP><P><CENTER>'.$article["receipts"].'</TD><TD WIDTH="9%" VALIGN=TOP><P><CENTER>'.$article["coop_prog"].'</TD><TD WIDTH="9%" VALIGN=TOP><P><CENTER>'.$article["tcmba"].'</TD><TD WIDTH="9%" VALIGN=TOP><P><CENTER>'.$article["ch_starts"].'</TD><TD WIDTH="9%" VALIGN=TOP><P><CENTER>'.$article["partners"].'</CENTER></TD></TR>';
}
?>
I have used this general query without problem in this format -
$sql = "SELECT * FROM news ORDER BY name";
But when I try to get input from the form and use that input to build the query it seems to return a NULL. The ($_POST[name]) returns the value entered in the input until it is used in the query format. Then it seems to return a NULL. I'm guessing there is some conversion function to keep this from happening but I have not found the solution.
What am I doing wrong?