willpeavy Posted November 29, 2008 Share Posted November 29, 2008 When I call a function, it successfully creates a new row and inserts the users email, but the random number (password) column is blank in my database. Any ideas what I'm missing here? $randompassword = rand(1000001, 9999999); ... mysql_query("INSERT INTO mydatabase (password, email) VALUES('', '$randompassword', '$usersemail') ") or die("cannot update"); Link to comment https://forums.phpfreaks.com/topic/134724-solved-insert-random-number-into-mysql/ Share on other sites More sharing options...
corbin Posted November 29, 2008 Share Posted November 29, 2008 mysql_query("INSERT INTO mydatabase (password, email) VALUES('', '$randompassword', '$usersemail') ") or die("cannot update"); Your column list.... password, email. Link to comment https://forums.phpfreaks.com/topic/134724-solved-insert-random-number-into-mysql/#findComment-701539 Share on other sites More sharing options...
willpeavy Posted November 29, 2008 Author Share Posted November 29, 2008 Thanks for the quick reply corbin. I made a typo in my previous post. This is what I have, but the password column is still blank: (id, password, email) VALUES('', '$randompassword', '$usersemail') ") If I write it like this, it will make an entry into the password column. But what I really need is a random number... (id, password, email) VALUES('', '123abc', '$usersemail') ") Link to comment https://forums.phpfreaks.com/topic/134724-solved-insert-random-number-into-mysql/#findComment-701559 Share on other sites More sharing options...
cooldude832 Posted November 29, 2008 Share Posted November 29, 2008 try <?php $pass = rand(1000001,9999999); $q = "INSERT INTO `mydatabase` (password,email) VALUES('".$pass."', '".$usersemail."')"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); ?> Link to comment https://forums.phpfreaks.com/topic/134724-solved-insert-random-number-into-mysql/#findComment-701562 Share on other sites More sharing options...
willpeavy Posted November 29, 2008 Author Share Posted November 29, 2008 @cooldude832 That worked perfectly! Thank you. Link to comment https://forums.phpfreaks.com/topic/134724-solved-insert-random-number-into-mysql/#findComment-701565 Share on other sites More sharing options...
willpeavy Posted November 29, 2008 Author Share Posted November 29, 2008 I was experimenting around some more and found this works: (id, password, email) VALUES('', '$pass', '$usersemail') ") So it works fine when the rand() function is set equal to $pass, but it doesn't work when rand() is set equal to $randompassword. Any clues why? I'm new to PHP (as you may have already guessed), and can't find documention on php.net about this being a protected variable name. I'm wondering if it is a configuration issue? (I'm running my script on a shared hosting account). Link to comment https://forums.phpfreaks.com/topic/134724-solved-insert-random-number-into-mysql/#findComment-701577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.