各位高手大家好,最近小弟用PHP做一个图书管理系统的毕业设计,但是由于出错,不知是什么原因,还望高手能够帮忙解答,小弟不胜感激,代码如下:
config.php
<?
global $hostname,$dbuser,$dbname,$dbpassword,$book_table,$send_table,$user_table;
 $hostname="localhost";
 $dbname="book";
 $dbuser="root";
 $dbpassword="root";
 $db=mysql_connect($hostname,$dbuser,$dbpassword) or die("数据库连接错误!");
  mysql_select_db($dbname,$db);
 $book_table="book_list";
 $send_table="book_lend";
 $user_table="book_user";
?> 
<?php 
//用户身份验证
include "config.php";
$query=mysql_query("select * from $book_user where user_name='$user' and user_pass='$password'");
$num=mysql_num_rows($query);                   //出错的地方代码if ($num == 0)          
{
   include "header.php";
   echo "请你确认用户名和密码是否正确?<br><br>";
   echo "<a href=index.php>重新填写</a><br><br>";
  
}
else
{
    setcookie("cookie_pass", "$password", time()+10000, "/");
    setcookie("cookie_user","$user",time()+10000,"/");
include "header.php";
    echo $user ;
echo "你好恭喜你!<br><br>";
echo("<HTML><META http-equiv=\"refresh\" content =\"0;url=book_list.php\"></HTML>");}
include "foot.php";
?>

解决方案 »

  1.   

    应该是sql语句的问题,你把$query打印出来放到数据库里面试试sql语句对不。
      

  2.   

    select * from $book_user where user_name='$user' and user_pass='$password'没看错,应该是$user_table吧;
      

  3.   

    也可以把$book_user 改成book_user
      

  4.   

    $book_table="book_list";
     $send_table="book_lend";
     $user_table="book_user";
    这是你的3个表,看得比较明白
    可是你这个select * from $book_user where user_name='$user' and user_pass='$password'
    里的$book_user是那个表呢?写错了大哥