
Search:And that is basically all the code we have to write for the form. Now the hard part, writing the processing. Open up a new file and save it as search.php that is in the same folder as the form code above. Essentially, this tutorial is exactly the same as the one on "Displaying a Database" tutorial we have, except the mySQL command is different. Here is what we have to write in English for the processing:
<form method="post" action="search.php"> <input type="text" name="search" size=25 maxlength=25> <input type="Submit" name="Submit" value="Submit"> </form>
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","user","password");
//select which database you want to edit
mysql_select_db("spoono_news");
$search=$_POST["search"];
//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM news WHERE message LIKE '%$search%'");
//grab all the content
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns
$title=$r["title"];
$message=$r["message"];
$who=$r["who"];
$date=$r["date"];
$time=$r["time"];
$id=$r["id"];
//display the row
echo "$title <br> $message <br> $who <br> $date | $time <br>";
}
?>
Not too tough was it? If you have any questions, post on our board and we'll answer it as soon as we can.
Copyright © 2000-2009 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.