what is the best method to insert a search query into MySql
and check for double words? (for showing up the last searches and a collection of searches)
maybe something like this:
< ?php
/*------------------------------
Read and save the search quer开发者_如何学运维y
-------------------------------*/
$querystat = mysql_real_escape_string($_GET['q']);
$insertquery = "INSERT INTO `query` ( `query`) VALUES ( '$querystat');";
mysql_query($insertquery, $db);
}
?>
but how to check for double words?
If you don't like a field to contain duplicated entries, you have to define it as UNIQUE.
Then you would issue your connands just the way you suggested:
$querystat = mysql_real_escape_string($_GET['q']);
$insertquery = "INSERT INTO `query` ( `query`) VALUES ( '$querystat');";
$res = mysql_query($insertquery, $db);
if (!$res) echo 'Insert faild. Most likely query already exists';
精彩评论