如何编写这个mysql查询,
SELECT * FROM `content`WHERE `language_option_tag` LIKE "%English%"
进入 php 代码,我只选择用户通过 FORM 发布的数据
$sql .= 'SELECT * FROM `content` WHERE `language_option_tag` LIKE "%' .$lang_name. '%" ;
$lang_name = $_POST['your_lang'];
$sql = "SELECT * FROM content WHERE `language_option_tag` LIKE '%$lang_name%'" ;
$lang_name = mysql_real_escape_string($_POST['selected_your_lang']);
$sql = "SELECT * FROM content WHERE `language_option_tag` LIKE '%$lang_name%'";
注意:当您从表单传递数据时,请始终使用 mysql_real_escape_string() 来停止 SQL 注入。
你错过了一个 bcaktick,也许这只是一个错字,但这会导致错误,而且你使用的方式应该不同,更改如下
$sql .= 'SELECT * FROM `content` WHERE `language_option_tag` LIKE '% .$lang_name. %' ;
^here is missing backtick `. ^ here there was a mistake
那么我想记住你有风险sql injection
,看看这里如何防止 PHP 中的 SQL 注入?. 您应该使用准备好的陈述来避免任何风险
$dbconnection= mysqli_connect("localhost", "my_user", "my_password", "dbname");
$lang = $_POST["lang"];
$lang = mysqli_real_escape_string($dbconnection, $lang); // To prevent SQL injection
$sql = "SELECT * FROM content WHERE `language_option_tag` LIKE '%$lang%'" ;
关于mysqli的使用访问http://php.net/manual/en/mysqli.real-escape-string.php