dongliuliu0385
2013-09-04 00:06 阅读 41
已采纳

搜索引擎错误PHP和Mysql

Hi Guys I've got a problem in my search engine. Here's the code:

$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%'");

But the problem is that searchq takes only the value of LF.

Where is the problem in my code please?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongsi5381 dongsi5381 2013-09-04 00:07
    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";
    }
    

    You are assigning instead of comparing. Use == to compare strings

    See documentation here: http://php.net/manual/en/language.operators.comparison.php

    A side note, you should switch to PDO or mysqli and use prepared statements. mysql_ functions are deprecated.

    点赞 评论 复制链接分享

相关推荐