Benim koduyla yanlış bilmiyorum:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>
<body>
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dressoholic") or die(mysql_error());
if($_POST['form_submitted'] == '1'){
$actkey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
$birthdate = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
$usrname = mysql_real_escape_string($_POST['uname']);
$pswd = mysql_real_escape_string($_POST['password']);
$emaill = mysql_real_escape_string($_POST['email1']);
# gender moet nog gedaan worden!!!
$sql = "INSERT INTO users(username, fname, lname, email, password, activationkey, bdate, status) VALUES
('$usrname','$_POST[fname]','$_POST[lname]','$emaill','$pswd','$birthdate','$actkey','verify')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "An email has been sent to $_POST[email1] with an activation key. Please check your mail to complete registration.";
##Send activation Email
$to = $_POST['email1'];
$subject = " Dressoholic.com Registration";
$message = "Welcome to our website!\r\rYou, or someone using your email address, has completed registration at Dressoholic.com. You can complete registration by clicking the following link:\rhttp://localhost/dressoholic/register.php?$activationKey\r\rIf this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\ Dressoholic.com Team";
$headers = 'From: blabla@gmail.com' . "\r\n" .
'Reply-To: blabla@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
else {
##User isn't registering, check verify code and change activation code to null, status to activated on success
$queryString = $_SERVER['QUERY_STRING'];
$query = "SELECT * FROM users";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if ($queryString == $row["activationkey"]){
echo "Congratulations!" . $row["username"] . " is now the proud new owner of a Dressoholic.com account.";
$sql="UPDATE users SET activationkey = '', status='activated' WHERE (id = $row[id])";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
}
}
}
?>
</body>
</html>
Bu tam hatadır:
Error: Duplicate entry 'arnold-blabla@gmail.c-1987--22' for key 'username'
arnold is the username I entered. blabla@gmail.com is the e-mail I entered. 1987 the year of birth and 22 the day!
Ben PHP ve MySQL bir acemi olduğumu söylemeliyim. Teşekkürler.