日期:2014-05-17  浏览次数:20521 次

错误求解 大神们啊
<?php
if (isset($_GET['go'])) {
  require_once('connection.php');
  $conn = dbConnect('read');
  $searchterm = '%' . $conn->real_escape_string($_GET['search']) . '%';
  $sql = "SELECT * FROM zhuce WHERE User LIKE '$search'";
  $result = $conn->query($sql) or die($conn->error);
  $numRows = $result->num_rows;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>查询</title>
</head>

<body>

<form id="form1" method="get" action="">
 <strong>关键词:</strong><label for="search"></label>
  <input type="text" name="search" id="search">
  <input type="submit" name="go" id="go" value="查询">
</form>
<?php if (isset($numRows)) { ?>
<?php echo htmlentities($_GET['search'], ENT_COMPAT, 'utf-8'); ?></b>: <?php echo $numRows; ?></p>
<?php if ($numRows) { ?>
<table>
  <tr>
    <th scope="col">用户名</th>
    <th scope="col">生日</th>
    <th scope="col">邮箱</th>
    <th scope="col">固定电话</th>
    <th scope="col">移动电话</th>
    </tr>
  <?php while ($row = $result->fetch_assoc()) { ?>
  <tr>
    <td><?php echo $row['User']; ?></td>
    <td><?php echo $row['Birthday']; ?></td>
    <td><?php echo $row['Mail']; ?></td>
    <td><?php echo $row['Phone']; ?></td>
    <td><?php echo $row['Mobile_telephone']; ?></td>
      </tr>
  <?php } ?>
</table>
<?php }
} ?>
</body>
</html>
Fatal error: Call to a member function real_escape_string() on a non-object in D:\xampp\htdocs\zhuce\search.php on line 5

------解决方案--------------------
all to a member function real_escape_string() on a non-object i

程序语法都错了哈。。
------解决方案--------------------
$conn 实例化失效?检查包含路径是否正确。
------解决方案--------------------
 $conn->real_escape_string($_GET['search']) 
问题可能出现在这里。看看这个是否通了。