How can i get a random row in my database and not have it change? Im trying to add a simple anti-spam feature, and i have 25 number combinations in the mysql table, but as soon as I enter the same combo and click send on the form, it changes that random combo so it says that the anti-spam combo was not the same... I have: $asql = ("SELECT * FROM antispam ORDER BY rand() LIMIT 1"); $ars = mysql_query($asql); $acount = mysql_num_rows($ars); while ($combo = mysql_fetch_array($ars)) { $ncombo = $combo[Code]; PHP: and the code to check if the code entered by the user matches the random combination: else if ($antispam != $ncombo) { echo''.$ncombo.''; // Was just testing to see if it actually keeps the same number, and it doesnt } PHP: and then in the form, i have this: <? echo' '.$ncombo.''; ?><br> <input name='antispam' size='5' maxlength='5'><br><br> PHP:
Check this line.. $ncombo = $combo ;[/COLOR] I think it's should be [COLOR="Sienna"]$ncombo = $combo['code']; [/COLOR] Code (markup):
Im trying to add a simple anti-spam feature, and i have 25 number combinations in the mysql table, but as soon as I enter the same combo and click send on the form, it changes that random combo so it says that the anti-spam combo was not the same... I think you enter a combo is in the table but remember the query will pick random the code from the table....maybe that why this message appear "anti-spam combo was not the same"
This is not so much a programming issue as a logic issue. Yes, use the rand() function to make a selection to generate your form etc, but pass along another parameter - such as the id of the randomly selected object. When you submit the form the ID is passed, along with the entered data, and you look up the entered data using the ID to find the correct response in your database.