php错误但它在哪里?

时间:2011-08-17 08:51:09

标签: php html

确定Dreamweaver和我的本地主机服务器一直说他们是错误但我不知道在哪里请帮忙?

这是一个php脚本,用于判断用户是否已经拥有一个帐户,然后如果他没有,则会将他注册到数据库中

<html>
<head>
<style type="text/css">
p {color:white;font-size:20px;}
.toppa {width: 100%;background-color:#2D2D2D;}
</style>

<?php
//Database Information

$dbhost = "localhost";
$dbname = "a8423624_grubber";
$dbuser = "root";
$dbpass = "";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$username = $_POST['username'];  
$email = $_POST['email'];    
$password = md5($_POST['password']);
$repassword = md5($_POST['repassword']);

$month = $_POST['month'];  
$day = $_POST['day'];
$year = $_POST['year'];  

$Intro = 1;
$admin = "no";

if (!(empty($username) or empty($email) or empty($password) or empty($repassword))) 
{
//a Text field is empty
    if ($password == $repassword) {
     $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");  
     $checkuser1 = mysql_query("SELECT email FROM users WHERE email='$email'"); 
     $email_exist = mysql_num_rows($checkuser1);
     $username_exist = mysql_num_rows($checkuser);
              // checks email 
            if ($username_exist  > 0)
                      {
                      echo "<div class='toppa' align='center'>
                      <h1 align='Left'> Grubber </h1>
                      </div>
                      <p> You'r Name has been taken please try another Name. </P>";
                      include 'tryagain.html';
                      }
                     else
                      { 
                             if ($email_exist > 0)
                             {
                              echo "<div class='toppa' align='center'>
                              <h1 align='Left'> Grubber </h1>
                              </div>
                              <p> You'r Email has been taken please try another Email.</P>";
                              include 'tryagain.html';
                             }
                             else
                             {
                                $themes = ("http://grubber.host56.com/Themes/Grubber.gif");
                                $date = ("$year/$month/$day");
                                $proimg = ("http://grubber.host56.com/images/defaultprof.png");
                                $query = "INSERT INTO users (admin,themes,proimg,Birthday,Intro,email, username, password)
                                VALUES('$admin','$themes','$proimg','$date', '$Intro', '$email', '$username', '$password')";
                                mysql_query($query) or die(mysql_error());
                                mysql_close();
                                echo "<div class='toppa' align='center'>
                                <h1 align='Left'> Grubber </h1>
                                </div>
                                <p> Please sign in to test that your account works </P>";
                                include 'tryagain.html';
                                }

             else
            {
            echo "<div class='toppa' align='center'>
            <h1 align='Left'> Grubber </h1>
            </div>
            <p>You'r passwords are not the same please try again.</P>";
            }

}
else
{
     echo "<div class='toppa' align='center'>
                      <h1 align='Left'> Grubber </h1>
                      </div>
                      <p> Please fill in all fields </P>";
                      include 'tryagain.html';
}
    }
}
?>

1 个答案:

答案 0 :(得分:0)

首先,您应该启用error_reporting。 其次,您应该使用mysql_real_escape_string来清理您的输入(否则有害的人可以SQL inject),第三,您应该在SQL查询后使用or die (mysql_error());,如下所示:

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'") or die(mysql_error());  
$checkuser1 = mysql_query("SELECT email FROM users WHERE email='$email'") or die(mysql_error());

如果您的SQL查询失败,您将看到正确的错误。