php教程 用户注册实例代码,适合初学者
if($_POST[submit]){
checkusername($_POST[username]);
if($_SESSION["code"]==$_POST[code])
{
$username= str_replace(" ","",$_POST[username]);
$password=md5($_POST[password].ALL_PS);
$sql="INSERT INTO `member`.`user_list` (`uid`, `m_id`, `username`, `password`) VALUES (NULL, '$_POST[select]', '$username','$password' )";
mysql教程_query($sql);
echo "注册成功";
}
else
{
echo "验证码错误"."
";
session_destroy();
}
}
function checkusername($username)
{
$sql2 = "select uid from user_list where username='".mysql_escape_string($username)."'";
$result = mysql_query($sql2) or die ('ERROR: '.mysql_error());
if(mysql_num_rows($result)>0)
{
echo "该用户名已经存在,请更换!";
exit();
}
else{
echo "<script> location.href='reg.php'</script>";
}
}
?>