开发者

How to insert Search Query into MYSQL - Check for Double Words

开发者 https://www.devze.com 2022-12-26 04:28 出处:网络
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)

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';
0

精彩评论

暂无评论...
验证码 换一张
取 消