-2

WTF? - this is becoming a nightmare, just seem to get error after error.. Im willing to pay someone for their time just to help me achieve what seems to be the unachievable, please.. alls I want is a dropdown menu that selects data from a table according to its category and displays it.. HELP! :(

<form action="portfolio.php" method="post">
 <select onload="displayProject(this.value);" onchange="displayProject(this.value);">
  <option value='none'>All</option>
  <option value='1'>Fencing</option>
  <option value='2'>Driveway</option>
 </select>
</form>

<?php 

$db = new mysqli('localhost', 'wlarter_user', 'pw', 'wlarter_portfolio');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$option= $_POST['option'];

$queries = "SELECT * FROM image"; 
if ($option != 'none'){
 $queries = "SELECT * FROM image where category=".$option; 
}

$result=@mysqli_query($db,"$queries");

while($row = mysqli_fetch_array($result))
{
?>

<div class="box-portfolio"> <?php echo $row['Img']; ?> </div>


<?php
}                      
mysqli_close($db);
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135

4 Answers4

0

can you try like this.......

$result=@mysqli_query($db,"$queries");
V-T
  • 756
  • 2
  • 9
  • 22
0

Simply turn it around, is probably what you want:

$queries=$query;

into

$query = $queries;

FULL code:

<FORM action="portfolio.php" method="post">
    <SELECT onload="displayProject(this.value);" onchange="displayProject(this.value);">
        <OPTION VALUE='none'>All</OPTION>
        <OPTION VALUE='1'>Fencing</OPTION>
        <OPTION VALUE='2'>Driveway</OPTION>
    </SELECT>
</FORM>

<?php

$db = new mysqli('localhost', 'wlarter_user', 'pw', 'wlarter_portfolio');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$option= $_POST['option'];

$queries = "SELECT * FROM image";
if ($option != 'none'){
    $queries = "SELECT * FROM image where category=".$option;
}

$query=$queries;
$result=mysqli_query($db,"$query");

while($row = mysqli_fetch_array($result))
{
    ?>

    <div class="box-portfolio"> <?php echo $row['Img']; ?> </div>


<?php
}
mysqli_close($db);
?>
Xatenev
  • 6,383
  • 3
  • 18
  • 42
0

replace this line

$result=@mysqli_query($db,"$queries");

with this:

$result=@mysqli_query($db,$queries);

it may help..

Moax6629
  • 378
  • 4
  • 14
0

Because the result of a mysql query can be a resource or a boolean value (if it failed), you should check the result of your query like this after executing it:

if ($result !== false) {
    while($row = mysqli_fetch_array($result))
    {
        ?>
            <div class="box-portfolio"> <?php echo $row['Img']; ?> </div>
        <?php
    }
}
else {
    // do your error message stuff here
    echo mysqli_error($db);
}
Maximilian Riegler
  • 22,720
  • 4
  • 62
  • 71