June 10th, 2000, 08:47 AM
OK, I've tried adding something to a database project I'm working on whereby a random number gets generated by the PHP and added to the database. I stripped out this piece of code which is causing the trouble and made it into a program in its own rights. But it doesn't seem to work. I created a new table called test with one column which is an INT. So the idea is that every time I call this program a random number gets added to the table. But it doesn't work: I get a parse error on the last line of the program, which just contains ?>
MYSQL_CONNECT(localhost,username,password) OR DIE("Unable to connect to database");
@mysql_select_db("database") or die("Unable to select database");
$iNum = rand(100000000, 999999999);
$query = "INSERT INTO test VALUES($iNum)";
print "<b>$iNum</b> has been added. Click <a href=id.php3>here</a> to run the ****er again.;
June 10th, 2000, 09:40 PM
You're seeding the random number wrong. Try this (ripped right from the PHP manual no less :P)
// seed with microseconds since last "whole" second
$randval = rand();
To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson
June 11th, 2000, 08:02 AM
and... the reason you are getting a parse error on the last line is that you don't have a closing quote on your print statement.
June 11th, 2000, 01:28 PM
Thanks once again, I got one of my web developer friends onto it and he pointed me in the right direction: in the end I realised that the problem lay in the fact that I got the form variables mixed up with the mySQL column names. It's now fixed and working!
Thanks. TOPIC CLOSED
June 12th, 2000, 08:58 AM
What's wrong with srand (time()) ? Is it just that it only changes once a second?