php代码问题,数据库连接
<?php$searchtype=$_POST['searchtype'];$searchterm=$_POST['searchterm'];$searchterm=tr...
<?php
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype||!$searchterm)
{
echo 'You have not entered search details.Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db=new mysqli("localhost","swh","89233182",'books');
if (mysqli_connect_errno())
{
echo 'Erroe:Could not connect to database. Please try again later.';
exit;
}
$query = "select * form boks where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results=$result->num_rows;
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i<$num_results; $i++)
{
$row=$result->fetch_assoc();
echo '<p><strong>'.($i+1).'.Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}
$result->free();
$db->close();
大家请看上面的代码,无论我在本页面如何改变用户登录密码,页面均能连接(不显示连接失败错误)。
谁能告诉我我错在哪里了? 展开
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype||!$searchterm)
{
echo 'You have not entered search details.Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db=new mysqli("localhost","swh","89233182",'books');
if (mysqli_connect_errno())
{
echo 'Erroe:Could not connect to database. Please try again later.';
exit;
}
$query = "select * form boks where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results=$result->num_rows;
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i<$num_results; $i++)
{
$row=$result->fetch_assoc();
echo '<p><strong>'.($i+1).'.Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}
$result->free();
$db->close();
大家请看上面的代码,无论我在本页面如何改变用户登录密码,页面均能连接(不显示连接失败错误)。
谁能告诉我我错在哪里了? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询