Hi ,
I've been working for a while now on a registration form , and i can not seem to find out my problem...
Basically what i wanna do is force a user to agree to the terms , on a checkbox.
Now problem is , whatever i try to do , it does not work - the message i keep getting is 'You must agree to the terms' , even though i did check the checkbox.
Another thing i'd like to do is save the passwords as md5 , could it work with trim?
here's my code:
<html>
<?php
if (isset($_POST['username']))
{
$username = trim($_POST['username']);
}
if (isset($_POST['pw']))
{
$pw = trim($_POST['pw']);
}
if (isset($_POST['age']))
{
$age = trim($_POST['age']);
}
if (isset($_POST['email']))
{
$email = trim($_POST['email']);
}
if (isset($_POST['sig']))
{
$sig = trim($_POST['sig']);
}
if (isset($_POST['bnet']))
{
$bnet = trim($_POST['bnet']);
}
if (isset($_POST['game']))
{
$game = trim($_POST['game']);
}
if (isset($_POST['race']))
{
$race = trim($_POST['race']);
}
if (isset($_POST['pwcon']))
{
$pwcon = trim($_POST['pwcon']);
}
if (isset($_POST['emailcon']))
{
$emailcon = trim($_POST['emailcon']);
}
if (empty($username) || empty($pw) || empty($email) || empty($bnet) || empty($emailcon) || empty($pwcon))
{
die('ERROR:Not all required fields are filled.');
}
if ($pw!=$pwcon)
{
die('Unmatching passwords.');
}
if ($email!=$emailcon)
{
die('Unmatching emails.');
}
if ($_POST['cb_rules_agree']=='off');
{
die('You MUST agree to the terms !');
}
$con = mysql_connect('host' , 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db",$con);
$exists=mysql_query("SELECT username FROM players WHERE username='$username'");
if ($exists)
{
die('Such username already exists in the database. Please choose another one.');
}
else
{
$sql=sprintf("INSERT INTO players (username, pw , age , email , sig , bnet , game , race)
VALUES ('$username', '$pw', '$age', '$email', '$sig', '$bnet', '$game' , '$race')",
mysql_real_escape_string($username),
mysql_real_escape_string($pw),
mysql_real_escape_string($age),
mysql_real_escape_string($email),
mysql_real_escape_string($sig),
mysql_real_escape_string($race),
mysql_real_escape_string($bnet),
mysql_real_escape_string($game));
if (!mysql_query($sql,$con))
die ('Error: '. mysql_error());
mysql_close($con);
echo "You have registered successfully";
}
?>
</html>
thanks ahead guys =)