How is it possible that this function below inserts two rows in my database?
//called like
save_session_db($_SESSION['user_id']);
function save_session_db($session){
include('includes/db-connect.php');
$connectionInf开发者_运维技巧o = array( 'Database' => 'Belior');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if($conn){
$date = date('l jS \of F Y');
$_SESSION['model_start_date'] = $date;
$tsql = "INSERT INTO User_Session (user_id, date_created) VALUES ('$session', '$date')";
echo 'insert--<br>'.$tsql;
if(sqlsrv_query($conn, $tsql)) {
return true;
}else{
return false;
}
}else{
return false;
}
sqlsrv_close($conn);
}
This function is not called from anywhere else. When I comment the function call above nothing gets inserted into DB. And PHP does not complain about invalid function call, meaning it doesn't get called from anywhere else.
When I uncomment the function call two rows get inserted!!
Thanks all for any help. I am sure its something simple, I just can't figure it out. It was working before, I can't remember what I tweaked.
Update
It looks as if every single page that I have gets loaded twice?! Why? I don't have a htaccess file anywhere that does this?
127.0.0.1 - - [06/Jan/2010:18:34:00 +0000] "GET /webs/end/create.php HTTP/1.1" 200 44830
127.0.0.1 - - [06/Jan/2010:18:34:06 +0000] "GET /webs/end/create.php HTTP/1.1" 200 44830
Is it possible that the code that call this function is called twice? For example, if your page is reload two times for some reason or another? Try to put some echo in the code that call this function. Maybe you'll get your answer.
If it truly is only being executed once, then it would seem to indicate something going on at the server. The table User_Session
could have a trigger that adds an additional row, for example. Although, that seems like something you would probably know about.
精彩评论