I am using this code for registering users, but it is not working. It always echos "Registration failed." I tried many times but nothing works
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";
}
}
}
}
below is table structure
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 ;
Does anyone know what the problem is?