Jump to content


Random Number to verify Subscriber

  • Please log in to reply
2 replies to this topic

#1 romio

  • Members
  • PipPip
  • Member
  • 28 posts

Posted 17 March 2006 - 07:20 AM

I have developed a simple newsletter subscriber where the admin can login and send to all active subscribers an email. What I need to do is create my own random procedure in order to send the new subscribers a link to active him/her self, I have an overall idea but not sure how to implement it, would it be better to have a separate table or just use the same table by adding a new filed?

Here are my thoughts up to now:

This is my code, which adds a new subscriber:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "subscribe")) 
            $first_name = $_POST['first_name'];
            $last_name = $_POST['last_name'];
            $email = $_POST['email'];
            $phone = $_POST['phone'];
            $street_address = $_POST['street_address'];
            $postal_code = $_POST['postal_code'];
            $province = $_POST['province'];
            $town = $_POST['town'];
            $country = $_POST['country'];

            $query = "INSERT INTO subscribers (first_name, last_name, email, phone, street_address, postal_code, province, town, country) VALUES ('$first_name', '$last_name', '$email', '$phone', '$street_address', '$postal_code', '$province', '$town', '$country')";
            mysql_select_db($database, $dbcnx);
            mysql_query($query) or die('Error, insert query failed');
            $headers .= "Miramare Beach Hotel"; 
            $headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
            $recipient = $email;
            $subject = "News letter Subscribtion";
            $message = "You have been added Successfuly";
            $msg = wordwrap( $msg, 1024 );
            mail($recipient, $subject, $message, stripslashes($msg), $headers);
            echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url='../../../?page=thanks.php'\">";

Can I add simply this link before the insert statement (I have also edited the insert query:



DECLARE Random_Num int;
DECLARE Upper_Num int;
DECLARE Lower_Num int

SET Lower_Num = 1
SET Upper_Num = 999999
SELECT  Random_Num = Round(((Upper_Num - Lower_Num - 1) * Rand() + Lower_Num), 0)


$query = "INSERT INTO subscribers (first_name, last_name, email, phone, street_address, postal_code, province, town, country, random_num) VALUES ('$first_name', '$last_name', '$email', '$phone', '$street_address', '$postal_code', '$province', '$town', '$country', 'Random_Num')";


#2 Kris

  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 March 2006 - 11:02 AM

You could make things easier for yourself by running their email address through md5() and then using that output as a "random" string - I assume the email address is a unique field. One less field in the database to worry about matching up...

#3 skatermike21988

  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 19 March 2006 - 11:48 AM

[a href=\"http://www.phpfreaks.com/tutorials/40/3.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/40/3.php[/a]

thereis something similar it talks about members area's but it generates a random password in md5 and sends a link for user to activate their membership. you can manipulate the code to ur needs

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users