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 を使用してゲームの Web サイトを作成しています...だから、おそらくすぐにここに戻ってくるでしょう xD)