Jump to content

confirmation number


kiki

Recommended Posts

$query = "SELECT confirmation FROM some_table";
$result = mysql_query($query);
while (list($confirmation) = mysql_fetch_assoc($result)) {
   $codes[] = $confirmation;
}
do {
     $confirm = md5(uniqid(rand(), true));
} while (in_array($confirm, $codes));

 

You could do something like that to make sure they're not in the DB.

Link to comment
https://forums.phpfreaks.com/topic/121615-confirmation-number/#findComment-627322
Share on other sites

 

that seems to work but how would i enter that into mysql database?

 

this is what i use

 

<?php
$con = mysql_connect("host","user","password"); 
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("table", $con); 
$string=mysql_real_escape_string($_POST['confirmation']);
$sql="INSERT INTO volunteer 

(confirmation,) VALUES 

('$string',)"; 


if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
?>

 

is the confirmation the "$string" ? is that what im trying to enter into my database?

Link to comment
https://forums.phpfreaks.com/topic/121615-confirmation-number/#findComment-627364
Share on other sites

Use mine to ensure unique confirmation numbers.  Also, add make sure the column is declared as UNIQUE in MySQL for extra reassurance.

 

when i put

 

$query = "SELECT confirmation FROM some_table";
$result = mysql_query($query);
while (list($confirmation) = mysql_fetch_assoc($result)) {
   $codes[] = $confirmation;
}
do {
     $confirm = md5(uniqid(rand(), true));
} while (in_array($confirm, $codes));

 

nothing shows up? do i just post it in the php file or something? sorry im kind of not good at this stuff.

 

and how do i make "sure the column is declared as UNIQUE in MySQL" ?is it the type, Collation?

Link to comment
https://forums.phpfreaks.com/topic/121615-confirmation-number/#findComment-627459
Share on other sites

It would probably be better to do:

[code=php:0]
do {
    $code = md5(uniqid(rand(), true));
} while(mysql_num_rows(mysql_query("SELECT 1 FROM some_table WHERE code = '{$code}'"));

 

Pulling the entire table is overkill.  What if there were a thousand rows?

 

okay when i just put that down. and click on submit button from the form it just takes me to a blank page. so i guess thats some error? basically i just need something to give a confirmation number and put it into my mysql database... did i do something wrong? am i suppose to put more then just that in?

Link to comment
https://forums.phpfreaks.com/topic/121615-confirmation-number/#findComment-627486
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.