在多个列中搜索多个项目

编程入门 行业动态 更新时间:2024-10-08 10:55:31
本文介绍了在多个列中搜索多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在表单中有6个选择项.我想在MYSQL DB中搜索那些6.如果只使用一个结果,我可以检索结果,例如:

I have 6 select items in a form. I want to search those 6 in MYSQL DB. I can retrieve results if I use only one, like:

$result = mysql_query("SELECT * FROM wsinmuebles WHERE Property_Type LIKE '%{$_POST['Property_Type']}%'");

但是当我尝试更多时,我没有结果!

But when I try more, I get no results!

$result = mysql_query("SELECT * FROM wsinmuebles WHERE Property_Type LIKE '%{$_POST['Property_Type']}%' AND Estado LIKE '%{$_POST['Estado']}%' AND Ciudad LIKE '%{$_POST['Ciudad']}%' AND Urbanizacion LIKE '%{$_POST['Urbanizacion']}%' AND Operacion LIKE '%{$_POST['Operacion']}%' AND Precio_bsf LIKE '%{$_POST['Precio_bsf']}%'");

这来自于POST方法的表单.

This comes from a form by the POST method.

我需要在MYSQL DB中查找Property_Type,Estado,Ciudad,Urbanizacion,Operacion和Precio_bsf变量,并仅接收与所有这些值匹配的结果.

What I need is to look for Property_Type, Estado, Ciudad, Urbanizacion, Operacion and Precio_bsf variables in MYSQL DB, and receive only the results that match all those values.

推荐答案

不要在条件之间使用或使用Or,毕竟,您应该知道串联字符串和执行查询可能会导致SQL注入,这是在代替搜索的情况下字符串我结束您的查询并执行给定的操作,例如'和1 = 1;删除wsinmuebles",如果这是我的搜索查询,您将丢失所有数据.

Dont use And use Or between criteria, and after all you should know that concatenating strings and executing queries is giving possible SQL Injection, that is when instead of your search string I end your query and execute given action, for example "' and 1=1; delete wsinmuebles" if this is my serach query you will lose all your data.

$result = mysql_query("select * from tbl1 where Name='".mysql_escape_string ($_POST["value"]."'" );

更多推荐

在多个列中搜索多个项目

本文发布于:2023-11-28 20:22:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!