I have recently started programing for fun so sorry if the resolution to this problem is something simple.
I have a mysql table that has customer sales tickets stored in it. What I am trying to do is get it so that you can refine the tickets shown by a drop down list. I am able to populate the drop down list from the mysql table but when I click submit to filter out and display by the customer name selected. I get the following error:-
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\result.php on line 16
Below are the two PHP pages that i use. The first page is where the drop down is populated.
<?php
//db connection
mysql_connect("********","********","********");
mysql_select_db("salesys");
//query
$sql=mysql_query("SELECT DISTINCT CustomerName FROM ticket ORDER BY CustomerName ASC");
if(mysql_num_rows($sql)){
$select= '<select name="select">';
while($rs=mysql_fetch_array($sql)){
$select.='<option value="'.$rs['CustomerName'].'">'.$rs['CustomerName'].'</option>';
}
}
$select.='</select>';
?>
<form name="input" action="result.php" method="POST">
<?php echo $select; ?>
<input type="submit" value="Submit">
</form>
And below is the second page.
<?php
$customerName = $_POST['select'];
echo "Showing Results For: ", $customerName;
echo "<BR>";
echo "<BR>";
$con=mysqli_connect("localhost","root","********","********");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM ticket WHERE CustomerName = $customerName");
while($row = mysqli_fetch_array($result))
{
echo $row['TicketID'] . " | " . $row['CustomerName'] . " | " . $row['BriefDesc'];
echo "<br>";
echo "<br>";
}
mysqli_close($con);
?>
Any help would much be appreciated.