I am trying to reflect the records from MySQL database using PHP. The code goes like this (Database is connected and selected)
Query.php -> This file reflect the distinct category(since I have multiple values of category) in select box from the database
<form action="process.php" method="post">
<select name="cat">
<?php
$sql="select distinct Category from tbl_1 order by Category asc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
echo "<option value=$row[Name]>$row[Category]</option>";
}
?>
</select>
<input name="" type="submit" />
</form>
process.php-> This file take the option selected by user in query.php and reflect Name and district accordingly.
<?php
$myValue =$_POST['cat'];
echo $myValue;
$mySqlStm = "SELECT Station, Name FROM tbl_1 WHERE Category = '.$myValue.'";
$result2 = mysql_query($mySqlStm) or die("Error:mysql_error()");
if(mysql_num_rows($result2) == 0)
{
echo("<br/>No Records Found");
}
ELSE
{
echo "<table border='1'>";
//ECHO THE RECORDS FETCHED
while($row = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td>" . $row['Station'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "</tr>";
}
echo "</table>"; }
?>
PROBLEM-> On running the query.php I think the process.php does not recieve the selected option from query.php and hence I get "No Records Found". My database have the data. Can anyone tell me the mistake here...