登记表不起作用

时间:2013-05-22 15:37:00

标签: php mysqli

我正在使用此代码注册用户,但它无效。它始终回应“注册失败”。我尝试了很多次但没有任何作用

if(isset($_POST['sub']))
{
    $uname = $_POST['uname'];
    $email = $_POST['email'];
    $pass_hash = PassHash::hash($_POST['pass']);

    $sq="SELECT * FROM user WHERE username='$uname'";
    //echo $sq;
    $re=mysqli_query($link,$sq);
    if(mysqli_num_rows($re)>0)
    {
        echo "Username  already taken !";
    }
    else
    {
        $SQ = "SELECT * FROM user WHERE email='$email'";
        //echo $SQ;
        $res=mysqli_query($link,$SQ);
        if(mysqli_num_rows($res)>0)
        {
            echo "Email already taken !";
        }
        else
        {
            $SQL = "INSERT INTO user(username,email,password) VALUES('$uname','$email','$pass_hash')";
            //echo $SQL;
            $result = mysqli_query($link,$SQL);
            if(!$result)
            {
                echo "Registration failed !";
            }
            else
            {
                echo"register done";
            }
        }
    }
}

下面是表格结构

CREATE TABLE `user` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(20) NOT NULL,
  `password` varchar(100) NOT NULL,
  `email` varchar(20) NOT NULL,
  `status` int(11) default '0',
  `sdate` date NOT NULL,
  `s_type` varchar(2) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  PRIMARY KEY  (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

有谁知道问题是什么?

1 个答案:

答案 0 :(得分:2)

您的表格中有很多not null个字段,但您没有为它们分配任何值,因此您的insert查询失败。