kiki Posted August 27, 2008 Share Posted August 27, 2008 is there a way to use php to make a confirmation number after a form is filled up and they are brought to a confirmation page? and have the confirmation number be able to be put into a mysql database? Link to comment https://forums.phpfreaks.com/topic/121615-confirmation-number/ Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 $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 More sharing options...
The Little Guy Posted August 27, 2008 Share Posted August 27, 2008 Something like this? http://phpsnips.com/snippet.php?id=24 Link to comment https://forums.phpfreaks.com/topic/121615-confirmation-number/#findComment-627325 Share on other sites More sharing options...
kiki Posted August 27, 2008 Author Share Posted August 27, 2008 Something like this? http://phpsnips.com/snippet.php?id=24 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 More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 Use mine to ensure unique confirmation numbers. Also, add make sure the column is declared as UNIQUE in MySQL for extra reassurance. Link to comment https://forums.phpfreaks.com/topic/121615-confirmation-number/#findComment-627372 Share on other sites More sharing options...
kiki Posted August 28, 2008 Author Share Posted August 28, 2008 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 More sharing options...
corbin Posted August 28, 2008 Share Posted August 28, 2008 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? Link to comment https://forums.phpfreaks.com/topic/121615-confirmation-number/#findComment-627468 Share on other sites More sharing options...
kiki Posted August 28, 2008 Author Share Posted August 28, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.