MySql Not Inserting :o
Posted: Fri Apr 25, 2008 10:25 am
Hello, I'm having a little problem of mysql not inserting data with INSERT. Everything else seems to work fine in the code. It is a register script. Code:
Create.php
Register.php
Any help would greatly be appreciated. Thank You! 
Create.php
Code: Select all
<?php
include("includes/Connect.php");
mysql_select_db("divnx5_web");
$username = $_POST['user'];
$password = sha1($_POST['pass']);
$password2 = sha1($_POST['pass2']);
$email = $_POST['email'];
if(!$_POST['register'])
{
echo "<form action='includes/Register.php' method='post'>
<fieldset id='register'>
<legend>Please fill out all the fields</legend>
<label for='user'>Username</label>
<input type='text' id='user' name='user' tabindex='1' />
<label for='pass'>Password</label>
<input type='password' id='pass' name='pass' tabindex='2' />
<label for='pass2'>Confirm Password</label>
<input type='password' id='pass2' name='pass2' tabindex='3' />
<label for='email'>E-Mail Address</label>
<input type='text' id='email' name='email' tabindex='4' />
<input type='submit' id='register' name='register' value='Register' tabindex='5' />
<input type='reset' id='reset' name='reset' value='Clear' tabindex='6' />
</fieldset>
</form>";
}
?>Code: Select all
<?php
include("Connect.php");
mysql_select_db("divnx5_web");
$username = $_POST['user'];
$password = sha1($_POST['pass']);
$password2 = sha1($_POST['pass2']);
$email = $_POST['email'];
function check($username)
{
$query = "SELECT * FROM `users` WHERE username = '$username'";
$result = mysql_query($query) OR die("$query: " . mysql_error());
if(mysql_num_rows($result) > 0)
{
echo "The username " . $username . 'is already taken';
$set = "1";
}
}
check($username);
if(empty($username))
{
echo "The username you entered encountered a problem.";
$set = "1";
}
if(empty($password) || empty($password2))
{
echo "The password you entered encountered a problem.";
$set = "1";
}
if(empty($email))
{
echo "The email you entered encountered a problem.";
$set = "1";
}
if($password != $password2)
{
echo "The password you entered do not match";
$set = "1";
}
if($set != 1)
{
mysql_query("INSERT INTO users(username, password, email, rank)
VAUES('$username', '$password', '$email', '1')");
echo "Welcome $username to the community! However, your registration process is not done yet.
Please check the email you provided us at $email for an activation link. Enjoy!";
mysql_close($con);
}
?>