.
Developer Spot - Web Development Tutorials
arrowDeverloper Spot  Tutorials  PHP  Publishing Newsletters Using PHP & MySQL - 3 
 
Development Tutorials
ASP
CGI & Perl
CSS
HTML
Java
JavaScript
Linux
PHP
XML




More Resources
Web Hosting Articles
Web Development News
PHP Manual
Create a Survey
Web Design Tutorials
Flash Tutorials
Rank Detective
Web Hosting Directory
Budget Web Hosting Linux Web Hosting Small Business Hosting
Windows Web Hosting Reseller Web Hosting Web Hosting Articles

Publishing Newsletters Using PHP & MySQL - 3

By Amrit Hallan
2004-03-28
Reader Rating: 3 out of 5
Bookmark Print Version
Publishing Newsletter Using PHP & MySQL - 3

For a quick wrap of the previous articles in the current series, go to:
Part 1
Part 2

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
http://www.yoursite.com/vemail.php?vmail=name@somesite.com.

If the person clicks on the link, the subsequent procedure verifies the email. So now let us write vemail.php.

<?php

$user_name="your_user_name";
$pwd="your_password";

$db=mysql_connect("localhost", $user_name, $pwd) or
die("I cannot connect to the database because " .
mysql_error());

mysql_select_db("newslet", $db);
?>

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 "name@somesite.com" exists in the table "subscribers".

<?php
$email=$_GET[vmail];
?>

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.

<?php
$query="update subscribers set active=1 where email='" . $email . "'";
?>

See that you enclose email in single quotes.

<?php
$result=mysql_query($query);
?>

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.

<?php
if(mysql_affected_rows()>0)
{
  echo "<h1>Congratulations!</h1>";
  echo "<p>Your email has been verified.</p>";
}
else
{
  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.


Article Pages:
Publishing Newsletter Using PHP & MySQL - 3

 Rate this article:   Poor          Excellent 


If you found this article interesting, you may want to read these as well:

» Protecting your PHP and HTML Source Code

» Publishing Newsletters Using PHP & MySQL - 4

» Publishing Newsletter Using PHP & MySQL - 2

» Publishing Newsletters Using PHP & MySQL

» Unix Webserver Crontab Basics

» Setting Up Apache, PHP & MySQL On Windows



 
Development Tutorials: CGI & Perl - CSS - HTML - Java - JavaScript - Linux - PHP - XML
More Resources: Web Hosting Articles - Web Development News - PHP Manual