PHP中我的MYSQL模糊查询语句到底错在哪里?请高手指教!

来源:百度知道 编辑:UC知道 时间:2024/05/27 21:00:41
<?php
require "head.php";
echo"<table width=\"992\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bordercolor=\"#EBF2FA\">";
echo"<tr>";
echo"<td height=\"24\" bgcolor=\"#C7DCF1\"><span class=\"STYLE18\">下列是与您查询的内容有关的帖子:</span></td>";
echo"</tr>";
echo"</table><br>";
$stt=$_POST[textfield];
$sql1="select * from $b_posts where title like '%$stt%'";
$result1=mysql_query($sql1,$link) or die(mysql_error());
$nums=mysql_num_rows($result1);
if($nums==0)
{
echo"<div align=\"center\"><span class=\"STYLE18\">没有您想查找的内容!</span></div>&q

格式写法上很多都不规范
你最好对$stt进行tirm处理 去掉首尾的空格
$b_posts应该是个表名 以变量的形式引入不太妥当

下面的例子是我学PHP第5天写的 你参考下 不过千万不要学这种写法 仅适合初学者
<?php
require_once("./include/config.php");
require_once("./include/usercheck.php");

if (!empty($_GET["cs_Id"]))
{
$cs_Id = $_GET["cs_Id"];
}
elseif (!empty($_POST["cs_Id"]))
{
$cs_Id = $_POST["cs_Id"];
}
else
{
$cs_Id = 1;
}

$keyword = "";

if (!empty($_POST["keyword"]))
{
$keyword = $_POST["keyword"];
}
elseif (!empty($_GET["keyword"])){
$keyword = $_GET["keyword"];
}
else
{
$keyword = "";
}

if(isset($cs_Id))
{
// $sql="select * from tbarticle where cs_Id=".$cs_Id."";
// //echo $sql;