Mon problème depuis ce matin (je sais j'avance pas vite
-J'ai commencé par un formulaire dans 'register.php' qui envoie ses données par POST dans 'sendmail.php'.
-Sendmail fait un contrôle basique de remplissage des champs, contrôle que l'email donné ne soit pas déjà dans la base de donnée, auquel cas on redirige l'utilisateur vers 'forgotten.php' et envoie un email avec un lien html sous forme "http://entreprise.com/validation.php?ID=[nombre]" (ID étant l'index auto-incrémenté) qui dans la théorie, une fois cliqué permettrait d'entrer un beau "validé" dans la table des utilisateurs.
Les problèmes :
-je suis VRAIMENT débutant en php mais je me soigne à l'aide du livre de Jean Carfantan "PHP & MySQL, versions 4 et 5", éditions Micro Applications, avril 2008.
-ma demande de $ID que je fais sous la partie "I try to get the user's ID" m'affiche la même chose depuis que j'ai rajouté cette ligne, c'est à dire "Resource id #4". La première fois que j'ai fait le test, c'était vrai,mais depuis je n'ai plus réussi à afficher la bonne variable. Ce problème me coince pour faire avancer le reste du site.
-quelqu'un pourrait me corriger mon script d'effaçage des données non validées depuis plus de 5 jours ? Il ne semble pas fonctionner non plus...
Je m'excuse de vous donner toutes ces lignes de code mais comme je suis vraiment débutant, je ne sais pas vraiment où se situe le problème (et puis c'est pas trop mal commenté encore...).
Je vous remercie de vous pencher sur ce code qui doit piquer les yeux des plus avertis !
<?
///We control that the email address doesn't already exist
include "common/connection.inc.php";
$email=htmlentities($_POST['prefix'])."@".htmlentities($_POST['subdomain']).".ac.uk"; //The email we are sending this text to
$sql1="select ID from safereg where email='$email'";
$result=mysql_query($sql1,$id_link);
$number=mysql_num_rows ($result);
if ($number >0){
$auth=1;
//$url='register.php';
//http_redirect($url);
include "register.php";
exit;
}
?>
<?
//We control that the fields are not exmpty
if(!empty($_POST['name']) and !empty($_POST['surname']) and !empty($_POST['mobile'])
and !empty($_POST['prefix']) and !empty($_POST['subdomain']) and !empty($_POST['residence'])
and !empty($_POST['room']) and !empty($_POST['question']) and !empty($_POST['answer'])){
/************ if the fields are not empty we write this on the screen*************/
echo '<h2 class="pagetitle"><br>Thank you!</h2>';
echo '<P class="text"><br>An email has been sent to ' . $email . '</p>';
echo '<p class="text">Please follow the link in this email to complete step 2 and validate your registration!</p>';
/*****************Here we feed the data into the database*************************/
$name=$_POST['name'];
$surname=$_POST['surname'];
$mobile=$_POST['mobile'];
$residence=$_POST['residence'];
$room=$_POST['room'];
$question=$_POST['question'];
$answer=$_POST['answer'];
$date=date(Ymd);
$sql2="INSERT INTO safereg (name, surname, mobile, email, residence, room, question, answer, date) VALUES ('$name', '$surname', '$mobile', '$email', '$residence', '$room', '$question', '$answer', '$date')";
mysql_query($sql2,$id_link) or die('Erreur SQL : '.mysql_error());
/********I try to get the user's ID******************/
$sql3="select ID from safereg";
$ID=mysql_query($sql3,$id_link) or die('Erreur SQL : '.mysql_error());
echo "$ID";
/*****************The email that is going to be sent*********************/
$mailheaders = "From: \"entreprise\" <[email protected]>\n";
$mailheaders .= "X-Sender: <[email protected]>\n";
$mailheaders .= "X-Mailer: PHP\n"; //mailer
$mailheaders .= "X-Priority: 1\n";
$mailheaders .= "Return-Path: <[email protected]>\n";
$mailheaders .= "Content-Type: text/html; charset=iso-8859-1\n";
/*****************Email text*******************/
$emailcontent = "Hello $name $surname,\n\n
Please click this link to complete the last step of your validation:\n
<a href=\"http://www.entreprise.com/activation.php?ID='$ID'\">Go to step 3</a>\n
If validation is not completed within 5 days your details will be deleted.
We thank you for your time,\n
Best regards / enjoy your safe,\n
The entreprise Team.";
/************End of email text*****************/
$emailcontent = nl2br($emailcontent);//formatting the text in html
$emailtext = "<HTML>\n";
$emailtext .= "<HEAD>\n";
$emailtext .= "<META NAME=\"GENERATOR\" Content=\"Microsoft DHTML Editing Control\">\n";
$emailtext .= "<TITLE>Step 2 - Registration</TITLE>\n";
$emailtext .= "</HEAD>\n";
$emailtext .= "<BODY><FONT face=Arial color=#68D263 size=4>\n";
$emailtext .= "<P><div align=\"center\"><STRONG>
Step 2 - registration with entreprise</STRONG></div></P></FONT>
<P><FONT color=#000000 face=Arial, Helvetica, sans-serif\" size=\"2\">\n";
$emailtext .= $emailcontent;
$emailtext .= "</FONT></P>\n";
$emailtext .= "</BODY>\n";
$emailtext .= "</HTML>\n";
/************Email function************************/
mail(
"[email protected],$email", /*And we send a nice email to the person here.
To add an email, just enter a coma, then the new email. No space between the two emails*/
'Step 2 - Safe registration with entreprise', // mail object
"$emailtext",
"$mailheaders");
/************End of email function*****************/
/***********We clear all unactivated DB entries that are older than 5 days********/
$5daysago = date("Y-m-d", mktime(0,0,0,date("Y"),date("m"),date("d")-5));
$sql4 = "DELETE FROM safereg WHERE activation='' AND date < $5daysago";
@mysql_query($sql4,$id_link);
}
else{
echo '<h2 class="pagetitle"><br>Error!</h2>'; // and that's what happend on the screen if the fields were empty
echo '<p class="text"><br>You have to fill in all the fields.</p>';
echo '<p class="text">Please go back to the precedent page...';
}
?>