0

嗨,伙计们,我的搜索引擎有问题。这是代码:

$types = mysql_real_escape_string($_GET['type']);

//Convertion de GET
if ($types = "air") {
    $searchq = "LF";
}elseif ($types = "huile") {
    $searchq = "OF";
}elseif ($types = "carburant") {
    $searchq = "KF";
}elseif ($types = "habitacle") {
    $searchq = "CF";
}elseif ($types = "eau") {
    $searchq = "WF";
}else{
    $searchq = "DF";
}


$searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
$query = mysql_query("SELECT * FROM tProduct WHERE sSearch LIKE '%$searchq%'") 
    or die("La Recherche est impossible");
$count = mysql_num_rows($query);
$result = mysql_query("SELECT * FROM tProduct WHERE sSearch LIKE '%$searchq%'");

但问题是searchq它只取 的值LF

请问我的代码中的问题在哪里?

4

1 回答 1

1
if ($types == "air") {
    $searchq = "LF";
}elseif ($types == "huile") {
    $searchq = "OF";
}elseif ($types == "carburant") {
    $searchq = "KF";
}elseif ($types == "habitacle") {
    $searchq = "CF";
}elseif ($types == "eau") {
    $searchq = "WF";
}else{
    $searchq = "DF";
}

您正在分配而不是比较。用于==比较字符串

请参阅此处的文档:http: //php.net/manual/en/language.operators.comparison.php

附带说明,您应该切换到 PDO 或 mysqli 并使用准备好的语句。mysql_ 函数已弃用。

于 2013-09-04T00:07:45.297 回答