0
我正在嘗試創建一個簡單的PHP註冊和登錄表單。 在將樣式和HTML添加到register.php文件之前,所有工作都按預期進行。 現在,當點擊註冊時,而不是說謝謝你註冊,沒有任何反應。在同一個文件中用HTML運行PHP腳本
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrapper">
<div class="form">
<?php
echo "<h1>Register</h1>";
$submit = $_POST['submit'];
// form data
$fullname = STRIP_TAGS($_POST['fullname']);
$username = STRIP_TAGS($_POST['username']);
$password = STRIP_TAGS($_POST['password']);
$repeatpassword = STRIP_TAGS($_POST['repeatpassword']);
$date = date("Y-m-d");
if ($submit)
{
if($fullname&&$username&&password&&$repeatpassword)
{
if ($password==$repeatpassword)
{
//check char length of username and fullname
if(strlen($username)>25||strlen($fullname)>25)
{
echo "Length of username or fullname is too long!";
}
else
{ //check password length
if (strlen($password)>25||strlen($password)<6)
{
echo "Password must be between 6 and 25 characters";
}
else
{ //register the user!
// encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);
//open database
$connect = mysql_connect("localhost", "Matt", "password123");
mysql_select_db("phpsignin");
$queryreg = mysql_query("
INSERT INTO users VALUES ('','$fullname','$username','$password','$date')`
");
die ("Thankyou for registering! <a href='index.php'> Return to login page</a>");
}
}
}
else
echo "Your passwords do not match!";
}
else
echo "Please fill in <b>all</b> fields!";
}
?>
<form id="login" action='register.php' method='POST'>
<fieldset>
<ol>
<li>
<label>Your Full Name:
<input type="text" name='fullname' value='<?php echo $fullname; ?>'>
</label>
</li>
<li>
<label>Choose a username:
<input type="text" name='username' value='<?php echo $username;?>'>
</label>
</li>
<li>
<label>Choose a password:
<input type="password" name='password'>
</label>
</li>
<li>
<label>Confirm Your Password:
<input type="password" name='repeatpassword'>
</label>
</li>
</fieldset>
<div id="buttonHolder">
<button type="submit" name="submit">Register</button>
</div>
</form>
</div>
</div>
</body>
</html>
您正在使用[**的**過時的數據庫API(http://stackoverflow.com/q/12859942/19068)和應該使用[現代替換](http://php.net/manual/en/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin 2013-02-19 20:02:56
什麼意思,什麼都沒有發生?白頁?你可能會得到一個異常,你檢查你的Apache日誌? – 2013-02-19 20:03:24
您正在使用MD5執行密碼散列處理,並且沒有鹽,這兩者都會使散列效率不佳。查看[PHP的密碼常見問題](http://www.php.net/manual/en/faq.passwords.php)。 – Quentin 2013-02-19 20:03:47