Jump to content

[SOLVED] Insert random number into MySQL


willpeavy

Recommended Posts

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

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

 

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).

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.