Here is the whole code as I tried it now. Only site name and such is not here.
This is what happens:
It does the 'if some field is not filled in' ok.
It does the 'if the username allready exists' ok.
And it sends the email with password ok.
And it writes the email (and the rest) to db ok!
But it ignores the 'if email allready exists'. 🙁
I have checked if the $email contains anything from the form which was filled in and it does. So that is not the problem.
Can it have something to do with the '@' - char?
BTW, the form is html. But that shouldn't have anything to do with it...?
Can one have some other approach? I'm so new at this that I am mostly still cutting and pasting code. :o
Thanks anyhow for trying to help.
Tiny
------------ code ----------------------
<?php
include("config.php");
$connection = mysql_connect("$server", "$db_user", "$db_pass");
$db = mysql_select_db("$database", $connection);
$query = "SELECT * FROM login where username='$username'";
$result = mysql_query($query, $connection);
$exuser=mysql_numrows($result);
// if some fields not is filled in send them back
if($username=='' OR $fname=='' OR $sname=='' OR $email=='')
{
echo 'Täytä kaikki tiedot. Klikkaa nettiselaimesi Peruuta-painiketta.';
exit();
}
// if the name is taken have them choose another
if($exuser==1)
{
echo 'Nimi on varattu. Valitse toinen.';
exit();
}
// if the email is in db refuse the register
$query = "SELECT * FROM login where email='$email'";
$result = mysql_query($query, $connection);
$exuser=mysql_numrows($result);
if($exuser==1)
{
echo 'Allredy registered.';
exit();
}
// if all is ok send mail
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$password = makeRandomPassword();
//$password = md5($random_password);
// Enter info into the Database.
$info2 = htmlspecialchars($info);
include("config.php");
$connection = mysql_connect("$server", "$db_user", "$db_pass");
$db = mysql_select_db("$database", $connection);
$query = "INSERT INTO login (username,password,fname,sname,email)".
"VALUES ('$username', '$password', '$fname','$sname', '$email')";
$sql = mysql_query($query, $connection);
if(!$sql){
echo 'Kirjatumisessa on tapahtunut virhe. Mailaa Tinyille.';
}
else {
$userid = mysql_insert_id();
$subject = "UH salasanasi";
$message = "Moi $fname
Tämä on automaattinen maili. Älä vastaa siihen!
Chattinimesi: $username
Salasanasi: $password
Seuraavaksi sinun tulee ladata chatti-ohjelman täältä:
[url]http://www.mysite.com/page.html[/url]
Terveisin,
Tiny";
mail($email, $subject, $message, "Lähettäjä: <tiny@mysite.com>\nX-Mailer: PHP/" . phpversion());
echo 'Salasanasi on nyt lähetetty maili-osoitteeseesi.';
}
?>