i want to display the food name and foodRate from my database but i cannot find out why i cannot do it with the below script. input type radio and name all of them button with different value data is inserted no problem and problem is in the first block of php error Notice: Undefined index: foodID in C:\wamp\www\web\polling\includes\resul and Warning: mysqli_query() expects parameter 1 to be mysqli, integer given i
$pollid = $_POST['foodID'];
$connection = include('connection.php');
$query = "SELECT * FROM polling WHERE foodID='$pollid'";
$q = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($q)) {
$id = $row[0];
$food = $row[1];
$foodRate = $row[2];
$userEmail = $row[3];
echo "<h1>$food</h1>";
echo "<h1>$userEmail</h1>";
}
?>
Below script is fine working good
if(isset($_POST['submit'])){
if(isset($_POST['button'])&&isset($_POST['email'])){
$query=$DBH->prepare('SELECT COUNT(*) FROM polling WHERE userEmail=?');
$query->bind_param('s',$_POST['email']);
$query->execute();
$query->bind_result($count);
$query->close();
if($count>0)echo"You've already used this email address to vote!";
else{
$update=$DBH->prepare('INSERT INTO polling (userEmail,foodRating) VALUES(?,?)');
$update->bind_param('si',$_POST['email'],$_POST['button']);
$update->execute();
$update->close();
echo"you have successfully voted! Thank you!";
}
}elseif(!isset($_POST['email']))echo"No email address enter";
elseif(!isset($_POST['button']))echo"You've not selected a vote";
}
?>