Publishing Newsletter Using PHP & MySQL – 3
By the end of the previous article we sent a verification email to whomever submits the subscription form. The email should contain the following message:
Please click on
If the person clicks on the link, the subsequent procedure verifies the email. So now let us write vemail.php.
$db=mysql_connect(“localhost”, $user_name, $pwd) or
die(“I cannot connect to the database because ” .
The above code has already been explained in http://www.bytesworth.com/learn/php00002.asp. If the person actually submitted the email, this email should be there in the database with the field active set to 0. The following commands set active to 1 if the email “firstname.lastname@example.org” exists in the table “subscribers”.
This command fetches the “GET” variable from the URL. If you are used to fiddling with forms you must be femiliar with using method=”post” and method=”get”. If not, go to http://www.bytesworth.com/learn/html00009.asp for a proper enlightenment on the subject. We move forward.
$query=”update subscribers set active=1 where email='” . $email . “‘”;
See that you enclose email in single quotes.
Whenever an SQL query is executed (the Talibanis just executed 8 Pakistani soldiers, so I find this word very violent), it affects one or more rows. If the email exists and if its respective active field is 0, then at least one row should be affected.
echo “<p>Your email has been verified.</p>”;
echo “<p>Sorry! You have either already verified your email, or you haven’t submitted your details for verification. Please go to the form and submitted your details.</p>”;
This ends the verification. In the fourth (perhaps the final of this series) article, we’ll see how the database is used to finally send the newsletter.