标题: 求助:有关PHP调用MYSQL做查询
allen.yyd
小试牛刀
Rank: 2
注册用户



UID 128266
精华 0
积分 0(积分有什么用?)
帖子 59
阅读权限 10
注册 2005-7-28
状态 离线
发表于 2006-4-13 20:10  资料  个人空间  短消息  加为好友 
求助:有关PHP调用MYSQL做查询

我的数据库books的用户名:bookorama,密码:bookorama123
在LINUX 下,查询一切正常
我有个PHP页面用来做查询,但是一直显示空白,请帮我看看代码什么地方有问题
还是我数据库建立有问题;



<html>
<head>
  <title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
  // create short variable names
  $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', 'bookorama', 'bookorama123', 'books');

  if (mysqli_connect_errno())
  {
     echo 'Error: Could not connect to database.  Please try again later.';
     exit;
  }

  $query = "select * from books 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 />rice: ';
     echo stripslashes($row['price']);
     echo '</p>';
  }
  
  $result->free();
  $db->close();

?>
</body>
</html>

顶部
不容错过的IBM 集群技术资源汇总
 



当前时区 GMT+8, 现在时间是 2008-5-17 14:00

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.076555 second(s), 5 queries

清除 Cookies - 联系我们 - Linux伊甸园 - Archiver - WAP