Jump to content

Random Number to verify Subscriber


romio

Recommended Posts

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:
[code]
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'\">";
            exit();
        }
?>
[/code]

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

CREATE PROCEDURE Random_Num

AS

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)

SET NOCOUNT ON

$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')";


SET NOCOUNT OFF
GO

[/code]
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.