Here is the html form:
<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>
And here is the PHP code on register.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.";
}
?>
I am a beginner in PHP and MySql. I have checked and rechecked all the usernames, passwords, databases, etc. The echo works and it says the registration is successful, but when I check my database there is no data.
Thanks SO much to everyone who answered!!! It works fine now :). As I said, I am new to all of this so most of the code was from snippets of tutorials and I just kind of skimmed it to see if it made sense. Thanks again! (I'm creating a game website with lots of PHP-MySql...so I'll probably be back here soon enough xD)