这是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)