PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?
//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>";
}
?>
Last edited by Benjamin on Sun Jun 07, 2009 11:29 pm, edited 2 times in total.
Reason:Changed code type from text to php.
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("host","username","password") or die("ERROR:" . mysql_error() );
//select which database you want to edit
mysql_select_db("a6756139_hexcode") or die("ERROR:" . mysql_error() );
$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%'") or die("ERROR:" . mysql_error() );
//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>";
}
?>
I added OR DIE(mysql_error() ) after the mysql functions
This will tell you where the script is failing, and the mysql error that is causing it.
ERROR:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EditorID LIKE '%ammo%'' at line 1