S
strawberry
Guest
Hi,
I am trying to create a simple search for the documents on my website.
The sql table is documents, and the three columns i want to search are anch, desc, and pdate.
It seems to parse the value (POST) across alright from te search form, however when it goes to show the values, it throws the 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 'desc LIKE '%test%' OR anch LIKE '%test%' OR pdate LIKE '%test%' ORDER BY pdate D' at line 1"
Below is my code, but i can't work out why the WHERE clause won't validate????
<?php
mysql_connect("localhost", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(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 documents WHERE desc LIKE '%$search%' ORDER BY pdate DESC")
or die(mysql_error());
//grab all the content
while($row = mysql_fetch_array($result))
{
//the format is $variable = $row["nameofmysqlcolumn"];
//modify these to match your mysql table columns
$anch=$row ["anch"];
$desc=$row ["desc"];
$id=$row ["id"];
$pdate=$row ["pdate"];
//display the row
echo "$anch <br> $desc <br> $pdate <br>";
}
?>
I am trying to create a simple search for the documents on my website.
The sql table is documents, and the three columns i want to search are anch, desc, and pdate.
It seems to parse the value (POST) across alright from te search form, however when it goes to show the values, it throws the 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 'desc LIKE '%test%' OR anch LIKE '%test%' OR pdate LIKE '%test%' ORDER BY pdate D' at line 1"
Below is my code, but i can't work out why the WHERE clause won't validate????
<?php
mysql_connect("localhost", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(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 documents WHERE desc LIKE '%$search%' ORDER BY pdate DESC")
or die(mysql_error());
//grab all the content
while($row = mysql_fetch_array($result))
{
//the format is $variable = $row["nameofmysqlcolumn"];
//modify these to match your mysql table columns
$anch=$row ["anch"];
$desc=$row ["desc"];
$id=$row ["id"];
$pdate=$row ["pdate"];
//display the row
echo "$anch <br> $desc <br> $pdate <br>";
}
?>