What I want is that when I select one meal that he show me the meal and the right price. Now he show me the meals but when i select one of these meals there are comes a error.
Error: Call to a member function fetch_assoc() on a non-object in
When I in mwvp.php this code removed. Then you see al prices that stored in database.
You can see under this the removed code en the orginal.
Change Meal.php
<?php
include ("connection.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Kantine</title>
<link rel="stylesheet" type="text/css" href="test.css">
<meta charset="utf-8">
<script src="js/jquery.min.js"></script>
<script type="text/javascript">
function getMeals(str) {
$('#meal_data').text("");
if (str == "select")
return;
$('#meal_data').load('mwvp.php?q='+str);
}
</script>
</head>
<body>
<div id="container">
<div id="logo"></div>
<div id="header">
<h1>Change Meal</h1></div>
<div id="menu">
<a href="Addmeal.php"><img src="Addmeal.png"/></a>
</div>
<div id="content">
<?php
$result = mysqli_query($con,"SELECT meal, price FROM Meals ");
echo '<select name="Meals"onchange="getMeals(this.value)"><option value="select">Choose Meal</option>';
while ($row = $result->fetch_assoc()) {
echo "<option value=\""."\">" . $row['meal']."</option>\n";
echo '<br />';
}
echo '</select>';
echo '<ul id="meal_data">';
echo '</ul>';
mysqli_close($con);
?></div>
<div id="footer"></div></div>
</body>
</html>
Original mwvp.php
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<?php
$q = $_GET["q"];
include("connection.php");
$result = mysqli_query($con, "SELECT meal, price FROM meals WHERE meal = " .$q);
while ($row = $result->fetch_assoc()) {
echo '<input name="price" type="text" value="'.$row['price'].'" />';
}
?>
</html>
Removed code in mwvp.php
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<?php
include("connection.php");
$result = mysqli_query($con, "SELECT meal, price FROM meals")
while ($row = $result->fetch_assoc()) {
echo '<input name="price" type="text" value="'.$row['price'].'" />';
}
?>
</html>