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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.