开发者

mysql data being inserted twice via php

I can't for the life of me figure out why this function is causing multiple entries into my database table...

When I run the function I end up with two records stacked on top of each one second apart

screen cap http://img132.imageshack.us/img132/5053/screenshot20100517at259.png

here is the function:

function generate_signup_token(){
    $connection = new DB_Connect(); // <--- my database connection class
    $ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); 
    $sign_up开发者_开发百科_token = uniqid(mt_rand(), true);
    $_SESSION['signup_token'] = $sign_up_token;
    $sign_up_token = mysql_real_escape_string($sign_up_token);
    $query = "INSERT INTO `token_manager` (`ip_address`, `signup_token`) VALUES ('$ip', '$sign_up_token')";
    mysql_query($query);
}

generate_signup_token();


The biggest piece of evidence that this function is being called more than once is the different signup tokens that are being generated.

Also, there is a one second difference between inserts which may be indicative of multiple page requests. If there is consistently such a time disparity, I'd investigate the access log. If there's only one page request, then the function must be called more than once somehow.


It looks like your function is fine. It appears that you are somehow calling the function twice. I'd suggest adding some debugging information to the function to figure out why. The function debug_print_backtrace might come in handy for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜