0
我一直在試圖讓這個註冊PHP的工作。我猜,我很近。但是有一個問題。結果總是一個重定向到主頁的按鈕(當你閱讀代碼時,你會知道我在說什麼)。如果你能找到問題,請告訴我。註冊php文件。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" id="jmtoday" class=" no_js">
<head>
<link href='icon.jpg' rel='icon' type='image/jpg'/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-language" content="en" />
<LINK REL=StyleSheet HREF="Mainstyles.css" TYPE="text/css"></link>
<Title>Sign up to JM Today</title>
</head>
<body>
<?php
$dbservertype='mysql';
$servername='localhost';
$dbusername='***';
$dbpassword='***';
$dbname='jmtdy';
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect("$servername","$dbuser","$dbpassword");
if(!$link){
die("Could not connect to MySQL");
}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
connecttodb($servername,$dbname,$dbusername,$dbpassword);
?>
<?php
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$password2=mysql_real_escape_string($_POST['password_confirmation']);
$todo=mysql_real_escape_string($_POST['todo']);
$email=mysql_real_escape_string($_POST['email']);
$fname=mysql_real_escape_string($_POST['fname']);
$lname=mysql_real_escape_string($_POST['lname']);
if(isset($todo) and $todo=="post"){
$status = "OK";
$msg="";
}
if(!isset($username) OR strlen($username) <3){
$msg=$msg."Username should be equal to or more than 3 characters long<BR/>";
$status= "NOTOK";
}
if(mysql_num_rows(mysql_query("SELECT username FROM users WHERE username = '$username'")or die (mysql_error()))){
$msg=$msg."Username already exists. Please try another one<BR/>";
$status= "NOTOK";}
if (strlen($password) < 3){
$msg=$msg."Password must be more than 3 charactors long<BR/>";
$status= "NOTOK";
}
if ($password <> $password2){
$msg=$msg."Passwords are not identical.<BR/>";
$status= "NOTOK";
}
if($status="NOTOK"){
echo "$msg<br/><input type='button' value='Retry' onClick='history.go(-1)'>";
}
else {
if(mysql_query("insert into users(username,password,email,fname,lname) values('$username','$password','$email','$fname','$lname')")or die (mysql_error())){
echo "Welcome, You have successfully signed up";
}
else {
echo "Database Problem, please contact Site admin";
}
}
?>
</body>
</html>
謝謝,這解決了問題! – 2010-12-20 15:53:23
沒問題,如果是正確的答案,你能接受嗎? – Andy 2010-12-20 16:12:14