-1

When I run the below code i get an error message C:\wamp\www\web\polling\includes\resul and Warning: mysqli_query() expects parameter 1 to be mysqli, integer given i <?php

    $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>";
    }
?>
Hamza
  • 37
  • 8

2 Answers2

0

You are missing a symbol in the statement

$query = "SELECT * FROM polling WHERE foodID='$pollid'";

s/b

$query = "SELECT * FROM `polling` WHERE foodID='$pollid'";

Kirk Powell
  • 908
  • 9
  • 14
  • will make absolutely no difference,. http://stackoverflow.com/questions/261455/using-backticks-around-field-names –  Jan 27 '15 at 22:55
0

Try mysqli_affected_rows() and see if $q is getting any data, if not it will never enter the while loop

Besides that it appears there is an issue in your connection, can you display how your connecting in connection.php?

I'm not sure but the two different types of mysql interactions on the same page raises a red flag. Do you have other pages that work with two types of mysql interactions?

EDIT 1: Try this

$connection = mysqli_connect("localhost", "root", "", "test");

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

This should work for your first script

Is there a reason your using two different types of mysql interaction?

Ian Thompson
  • 187
  • 1
  • 10
  • connect_errno) { echo "Failed to connect to MySQL: (" . $DBH->connect_errno . ") " . $DBH->connect_error; } ?> – Hamza Jan 27 '15 at 23:27
  • i an new to php so any recommendation will be welcomed. – Hamza Jan 27 '15 at 23:33
  • ^^^ edited,,,you can keep both connections if you close the first before opening the second one if it's not possible to run both of your queries off off one connection – Ian Thompson Jan 28 '15 at 01:02