Topic: "Unable to insert search results" aléatoire

Hello everyone,
I have got a problem with punBB with one of its possibilites.
Indeed, when I'm trying to "show recent posts", it often show this error message (debug mode activated) :

An error was encountered
File: \forum\search.php
Line: 413

PunBB reported: Unable to insert search results

Database reported: Duplicate entry '118449523' for key 1 (Errno: 1062)

Do you have any idea of where it could come from?
If you want to see this error, just refresh many times this URL : http://forum.sonata-arctica.info/search … n=show_24h

Re: "Unable to insert search results" aléatoire

Calico: Well, that defies odds hmm

$search_id = mt_rand(1, 2147483647);

That's the line that creates the search id. Basically, you're somehow getting the same random number

Re: "Unable to insert search results" aléatoire

Very strange indeed...
Do you have any solution to the problem?
This happens since I have installed IIS6 on Windows. Before that, I was using Apache2 with Linux.

Re: "Unable to insert search results" aléatoire

Well, you could change search_id to an auto_increment, alter the query to not insert search_id, and truncate the table smile

Re: "Unable to insert search results" aléatoire

Hmmm.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: "Unable to insert search results" aléatoire

Hmmm well it's a way of cheating smile but I would like to know if it's normal that I get the same random number ?
Theorically, it's something that should not happen isn't it ?

7 (edited by Calico 2005-08-29 21:18)

Re: "Unable to insert search results" aléatoire

I saw this information oh php.net about the mt_rand() function, maybe this case concerns me :

paulo at icreations dot com dot br
07-Jan-2005 01:28
Warning! Some times in windows platform (2000 and XP) mt_rand generates the same number. It happens to me in 3 machines (1xW2000 and 2xWXP) and in another two XP doesnt happens.

PHP Version: 4.3.4
All XP machines with SP2 and all 2000 machines with SP1.

I have to use a mt_srand function to correct this issue.

Hope this help someone.

But I saw that math_srand is optionnal since PHP 4.2.0... and I'm using PHP5..

Re: "Unable to insert search results" aléatoire

That might very well be the problem. Try inserting:

mt_srand((double)microtime()*1000000);

on the line right before

$search_id = mt_rand(1, 2147483647);

in search.php.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

9 (edited by Calico 2005-08-29 21:38)

Re: "Unable to insert search results" aléatoire

I just changed in search.php

$search_id = mt_rand(1, 2147483647);

to

mt_srand();
$search_id = mt_rand(1, 2147483647);

And it seems to work very well now !

I think the developers should correct this bug in the next release of punBB

Re: "Unable to insert search results" aléatoire

Calico: *looks up at the post before yours*

11

Re: "Unable to insert search results" aléatoire

Oupps lol wink

I didn't refresh the page sorry! smile His solution works well too ;-)

Thank you Rickard !

Re: "Unable to insert search results" aléatoire

Calico: Thing is, that is not the preferred behavior. The random number generator should be seeded only once. The fact that it helped you shows that there is a problem in PHP.

"Programming is like sex: one mistake and you have to support it for the rest of your life."