简体   繁体   English

搜索引擎错误PHP&Mysql

[英]Search Engine Bug 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 . 但是问题是searchq仅采用LF的值。

Where is the problem in my code please? 请问我的代码中的问题在哪里?

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 请参阅此处的文档: http : //php.net/manual/zh/language.operators.comparison.php

A side note, you should switch to PDO or mysqli and use prepared statements. 附带说明,您应该切换到PDO或mysqli并使用准备好的语句。 mysql_ functions are deprecated. 不建议使用mysql_函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM