Jump to content

search bar results


Cflax

Recommended Posts

hey guys, i have a search bar i am implementing into my navmenu but keeping getting errors returned and im not sure why

 

This is the code in my navmenu to display the search bar

echo '<form action="search.php" method="post">Search: <input type="text" name="term" /> <input type="submit" name="submit" value="Search"/>';

Here is the php file that query's the search
$term = $_POST['term'];
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
$query = mysqli_query("select * from ob_listings where subject like '%$term%' or description like '%$term%' ");
while ($row = mysql_fetch_array($dbc, $query)){
echo 'Subject: '.$row['subject'];
echo '<br/> Date: '.$row['date'];
echo '<br/> Price: '.$row['price'];
echo '<br/> City: '.$row['city'];
echo '<br/><br/>';
}

any help is much appreciated

 

here are the errors being returned

 

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 16

(line 16 is the $query)

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 17

(line 17 is the while loop)

Link to comment
https://forums.phpfreaks.com/topic/235167-search-bar-results/
Share on other sites

figured it out, for anyone that cares here is my corrected code in search.php

$term = $_POST['term'];
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
$query = "select * from ob_listings where subject like '%$term%' or description like '%$term%' ";
$data = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($data)){
echo 'Subject: '.$row['subject'];
echo '<br/> Date: '.$row['date'];
echo '<br/> Price: '.$row['price'];
echo '<br/> City: '.$row['city'];
echo '<br/><br/>';
}

 

Link to comment
https://forums.phpfreaks.com/topic/235167-search-bar-results/#findComment-1208565
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.