Technolust
Technolust

Reputation: 182

Warning : rand() expects parameter to be long

Getting the following error:

Warning: rand() expects parameter 2 to be long, array given in C:\wamp\www\honeydev\python.php on line 61

Following is the code:

58 $max_passno=$dbo->prepare("select count(*) from user_password"); //find the max. no of entries in user_password table
59 $max_passno->execute();
60 $row = $max_passno->fetch();
61 $no2 = rand(1, $row); //select a random number

Can someone suggest, what changes are required to resolve this please?

Upvotes: 0

Views: 3161

Answers (1)

Bitwise Creative
Bitwise Creative

Reputation: 4105

Read the error message again. It states, quite clearly, what the problem is and where it is.

rand(1, 999);

Parameter 2 needs to be a number. For some awesome reason, you threw an array in there. Pretty fun, but it won't work that way.

$max_passno=$dbo->prepare("select count(*) as count from user_password"); //find the max. no of entries in user_password table
$max_passno->execute();
$row = $max_passno->fetch();
$no2 = rand(1, $row['count']); //select a random number

For future reference, it may help to examine the variable in question.

var_dump($row);

Upvotes: 4

Related Questions