Help error when using php to search mysql database
Posted: Sun Jun 07, 2009 3:06 pm
i have a website that i am making and i want to search a my sql table but it comes up with an error.
please help code is below.
Form Code
search.php
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a6756139/public_html/search.php on line 17
please help code is below.
Form Code
Code: Select all
<form method="post" action="search.php">
<input type="text" name="search" size=25 maxlength=25>
<input type="Submit" name="Submit" value="Submit">
</form>Code: Select all
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","username","password");
//select which database you want to edit
mysql_select_db("a6756139_hexcode");
$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>";
}
?>