這裏是HTML表單:
<form action="register.php" METHOD=GET align="center">
<table border="2" align="center">
<tr>
<td>Desired Username:</td><td><input name="username" type="text" size"20"></input></td>
</tr>
<tr>
<td>Your Email:</td><td><input name="email" type="text" size"30"></input></td>
</tr>
<tr>
<td>Desired Password:</td><td><input name="password" type="password" size"20"></input> </td>
</tr>
<tr>
<td>Confirm Password:</td><td><input name="password2" type="password" size"20"></input> </td>
</tr>
</table>
<input type="submit" value="Register!" align="center"></input>
</FORM>
這裏是register.php PHP代碼:
<?php
$myServer = "localhost";
$myUser = "Censored";
$myPass = "Censored";
$myDB = "Censored";
//connection to the database
$conn = "mssql_connect($myServer, $myUser, $myPass)
or die('Couldn't connect to SQL Server on $myServer')";
//select a database to work with
$selected = "mssql_select_db($myDB, $conn)
or die('Couldn't open database $myDB')";
//add new user to DB
if($_GET["username"] && $_GET["email"] && $_GET["password"] && $_GET["password2"])
{
if($_GET["password"]==$_GET["password2"])
{
$sql="INSERT INTO Users(Username, Password, Email) VALUES('$_GET[username]','$_GET[password]','$_GET[email]')";
$result="mysql_query($sql,$conn) or die (mysql_error())";
}
if ($result)
{
echo "<h1 align='center'>Registration Successful!</h1>";
echo "<p align='center'>Click<a href='index.php'> here</a> to log in.</p>";
}
else echo "Oops! Something went wrong. Please <a href='http://www.canilosa.zxq.net/index.php'>go back</a> and fix it.";
}
?>
我在PHP和MySQL的初學者。我已經檢查並重新檢查了所有的用戶名,密碼,數據庫等等。回聲工作,它說註冊是成功的,但是當我檢查我的數據庫時,沒有數據。
非常感謝大家的回答!它現在工作正常:)。正如我所說的,我對所有這些都是新手,所以大部分代碼都來自教程片段,我只是剔除它,看看它是否有意義。再次感謝! (我創建一個遊戲網站,有很多PHP MySQL的的...所以我可能會回到這裏很快就好了XD)
使用'$ _GET ['username']'而不是'$ _GET [username]'。 – 2013-03-14 05:38:49
結合下面的所有答案。你會得到一個完美的解決方案。 – 2013-03-14 05:40:38
非常感謝所有回答的人!它現在工作正常:)。正如我所說的,我對所有這些都是新手,所以大部分代碼都來自教程片段,我只是剔除它,看看它是否有意義。再次感謝! (我正在創建一個有很多PHP-MySql的遊戲網站......所以我很快就會回到這裏xD) – Tulip 2013-03-14 05:55:05