1

I am very very new to PHP and MySQL, so please be nice :)

I am trying to make a search item at the top of my website that searches through an entire table, but gives you the option to select with field to search in.

I tried using the select tag and in didnt work?

Please help!

This is my html code below:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET"> 
<b>Enter Search Term:</b> <input type="text" name="term" size="50"> 
<select name="field">
<option value="name">Name</option>
<option value="surname">Surname</option>
<option value="post_title">Post Title</option>
</select>
<b>Results:</b> 
<input type="submit" value="Search"> </form>
<br /><br /><br />
<hr>

This is my php code in the same document:

<?php
mysql_connect("host url", "username", "password");
mysql_select_db("databasename");
$sql = mysql_query("SELECT * FROM data WHERE '%$_SHOW[field]%' LIKE '%$_GET[term]%'");
while($ser = mysql_fetch_array($sql)) { 
echo "<h2>$ser[post_title]</h2>";
echo "<h3>$ser[name], $ser[surname]</h3>";
echo "<h5>$ser[date]</h5>";
echo "<p>$ser[description]<p>";

}
?>

I need help please... Thanks in advance.

user3770518
  • 63
  • 2
  • 5

0 Answers0