我用下面的第一个php文件时,其他的弹窗都能正常显示,甚至会显示注册成功,唯一的问题是不能将数据输入数据库。但是我用右面第二个php文件时却可以将数据输入,大家帮我看看吧,看看第一个是哪里错了!第一个:<?php
//连接数据库
$link = mysql_connect("localhost", "root", "");
//判断连接是否成功
if (!$link) 
{
    die('Could not connect: ' . mysql_error());
}
//选择数据库
mysql_select_db("user",$link);
//判断姓名是否为空
if (!empty($_POST[username]))
{
 if (!empty($_POST[password]))
 {
    if (!empty($_POST[email]))
    { 
  if(!empty($_POST[cellphone]))
  {
          $username=($_POST[username]);
          $cellphone=($_POST[cellphone]);
          $email=($_POST[email]);
          $password=($_POST[password]);
          $newpassword=($_POST[newpassword]);
          $query="select username,email from person where username='$username' and email='$email'";
          $result=mysql_query($query);
          $num_rows = mysql_num_rows($result);
          if ($num_rows>0)
          {
            echo"<script language=\"JavaScript\">\r\n"; 
            echo " alert(\"The customer that you input someone already registered, please enter again!\");\r\n"; 
            echo " history.back();\r\n"; 
            echo "</script>"; 
            exit; 
          }
          else
      {
            if ($password==$newpassword)
            {
              $sql="INSERT INTO person (username,cellphone,email,password)VALUES('$username','$cellphone','$email','$password')"; 
              echo "<script language=\"JavaScript\">\r\n"; 
              echo " alert(\"Congratulations you register!\");\r\n"; 
              echo " location.replace(\"http://localhost/index.html\");\r\n";  
              echo "</script>"; 
              exit; 
             }    
             else
             {
               #echo "Your new password and confirmed new password do not match,please try again!";
               echo "<script language=\"JavaScript\">\r\n"; 
               echo " alert(\"Your new password and confirmed new password do not match,please try again!\");\r\n"; 
               echo " history.back();\r\n"; 
               echo "</script>"; 
               exit; 
             }
          }
      }
      else 
      {
        echo "<script language=\"JavaScript\">\r\n"; 
        echo " alert(\"You have not enter cellphone, please enter again!\");\r\n"; 
        echo " history.back();\r\n"; 
        echo "</script>"; 
        exit;  
  }
     }
     else 
     {
       echo "<script language=\"JavaScript\">\r\n"; 
       echo " alert(\"You have not enter email, please enter again!\");\r\n"; 
       echo " history.back();\r\n"; 
       echo "</script>"; 
       exit;  
      }
  }  else 
  {
    echo "<script language=\"JavaScript\">\r\n"; 
    echo " alert(\"You have not enter password, please enter again!\");\r\n"; 
    echo " history.back();\r\n"; 
    echo "</script>"; 
    exit;  
   }
}else 
{
 echo "<script language=\"JavaScript\">\r\n"; 
        echo " alert(\"You have not enter username, please enter again!\");\r\n"; 
        echo " history.back();\r\n"; 
        echo "</script>"; 
        exit;
}
?>
第二个:<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("user", $con);$sql="INSERT INTO person (username, cellphone, email,password)
VALUES
('$_POST[username]','$_POST[cellphone]','$_POST[email]','$_POST[password]')";if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "<script>alert(\"欢迎光临\");</script>"; mysql_close($con)
?>