Forum Moderators: coopster

Message Too Old, No Replies

Retrieve information from mysql, display it, and delete it?

Or any other way of getting the same results.

         

three08

1:34 pm on May 29, 2006 (gmt 0)

10+ Year Member



I'm hopping one of you may be able to help me, I have a list of user names and passwords (txt file) like this:

"0000000-0","00000000000"
"0000000-0","00000000000"
"0000000-00","0000000000"
"0000000-000","0000000000"

Threre are 500 lines like this and each one is to be issued only once.

I need to send them to my customers one at a time as they order and pay for their products, now I have a system in place that emails the products to them automaticly and would like to include the link to a password protected section of my page that they can get their user/pass from.

Is there a way I can add the user/pass infomation into a mysql db and have a script fetch 1 of the user/pass combo's from the db, display it on a webpage then delete the db entry so the same user/pass can't be reissued?

btw I don't expect anyone to write it for me, I just need some help as the only thing I've done with mysql and php is modding phpBB forums.

I know programs such as mailloop would be able to do this in a email instead of using mysql, but I am setting this company up, and I simple can't aford to buy the software until I start making more then $50 a week and besides I might learn something from this :)

Thanks in advance

[edited by: jatar_k at 5:26 pm (utc) on May 29, 2006]
[edit reason] no urls thanks [/edit]

wrightee

5:53 pm on May 29, 2006 (gmt 0)

10+ Year Member



I suggest something like this:

Add each user/pass to db. Additionally create colum of 'issued' (date) and 'used' (int).

When you issue a user/pass, stamp the date. That way 'SELECT user, pass from my_table where issued IS NULL LIMIT 0,1' will supply you with the next un-issued combination.

When someone tries to use their user/pass, 'UPDATE my_table set used=used+1', to see how many times it's been used; then you can lock it if they use it 'too much'.

Don't delete the user/pass from the db, customers will forget / lose / fib.

three08

11:32 am on May 31, 2006 (gmt 0)

10+ Year Member



Thanks for the fast reply, sorry it took so long for me to get back.

I've been given the code for the php file from that site I had linked in my original post, I have tweeked it to work with my host and db, but the problem I'm having now is I don't know how they had their db setup with the user/pass/used. I named the username colum "code" and the password colum "code2" then made a third colum and called it "used" but I don't know how to set them up.

Now it is displaying everything the way it should be but no username or password is displayed the email even gets sent. I have no idea whats wrong so if anyone might be able to help me out it would be great.
Here is the code I have to work with:

<?php


//lines are debug info
//$email = $_GET[email];

//echo phpinfo();

$sess = $PHPSESSID;
if ($sess) {
//Stop clicking the page error...
echo "Sorry - only one set of codes per user...";
exit;
}
session_start();



// get database connection
$db_link = mysql_connect('localhost', 'writer2w_test', 'user');//change these for your dbms
if ($db_link) mysql_select_db('writer2w_regcode'); //change these for your dbms

$sql_email = mysql_escape_string($email);
$query = mysql_query(" SELECT * FROM regcodes WHERE used = '0' LIMIT 1");//change table name for your dbms
$result_array = mysql_fetch_array($query);

if ($result_array){
mysql_query("UPDATE codes SET used = 1 WHERE pwd = '$result_array[pwd]' ");
$code = $result_array[usr];
$code2 = $result_array[pwd];
//echo "$code and $code2";


} else {
echo "No unused codes";
}


echo "<b>To access your ebooks, use the following codes:</b><br><br>";
echo "Username: $code <br>";
echo "Password: $code2";

mysql_close($db_link);



if ($email) {
$myname = 'Ebook Codes';
$myemail = 'craig@goodies-for-you.com';

$headers = "Your Ebook Codes \n";
$headers .= "MIME-Version: 1.0\r \n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
$headers .= "From: \"$myname\" <$myemail>\r \n";
$headers .= "Reply-To: \"$myname\" <$myemail>\r \n";
$headers .= "X-Priority: 3\r \n";
$headers .= "X-MSMail-Priority: High\r \n";
$headers .= "X-Mailer: Just My Server";

$message = "Use these codes to access your rudl ebooks.\r\n\n";
$message .= "Your ebook username: $code\r\n";
$message .= "Your ebook password: $code2\r\n";

mail($email, $headers,$message);
echo "<BR><BR><b>Ebook Codes Sent To:</b> $email";
echo "<BR><BR><BR><BR><BR><BR><BR><p align=center><a href=javascript:self.close()><img border=0 src=close_window.gif width=125 height=37></a></p></body>";
exit;
}

?>

three08

3:01 pm on May 31, 2006 (gmt 0)

10+ Year Member



ok got it all working now.