Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:25:13+00:00 2026-05-26T15:25:13+00:00

I have a strange problem with php scripts – mysql_affected_rows() sometimes returns 0 for

  • 0

I have a strange problem with php scripts – mysql_affected_rows() sometimes returns “0” for no reason.

There is a similar question @stackoverflow and answer to this question is:

MySQL only actually updates a row if there would be a noticeable difference before and after the updat.

But this is not my case. For example, if value before update is 1320402744 and value after update is 1320402944 mysql_affected_rows() anyway return “0”. Is this difference not enough noticable?

Below are 3 files. As you can see, all files include file “functions.inc.php” which calls function “online()”.

File “login.php” is working fine. It inserts a new row in “session” table correctly.

File “content.php” is working fine – it displays content and correctly runs function “online() in “functions.inc.php”.

Then I call file “test.php“. It deletes “something from sometable” correctly. Then it refreshes itself (Header(“Location: /test.php”);). After refreshing I am logged off.

I added this to “online()” function:

echo "affected_rows";

It returns 0.

I added more code to “online() function:

$checkuser = mysql_query("SELECT userid FROM session WHERE userid = '" . $_SESSION['id'] . "'") or die('Error');
$found = mysql_num_rows($checkuser);

echo $found;

 $result = mysql_query("UPDATE session SET time='$ctime' WHERE userid='".$_SESSION['id']."'") or die('Error');
    $affected_rows = mysql_affected_rows();
    if ($affected_rows != 1) @session_destroy();

echo $affected_rows;

The result is 1 and 0.

I checked the database. “time” field in session table has been updated.

So, I can’t understand how is it possible that the row exists, it updates correctly but mysql_affected_rows(); returns 0, and why this happends only if te same page has been refreshed.

functions.inc.php

<?php
@ob_start();@session_start();
@mysql_connect(C_HOST, C_USER, C_PASS) or die('Cant connect');
@mysql_select_db(C_BASE) or die('Cant select DB');

function online() {
$ctime = time()+1800;

if((isset($_SESSION['id']))&&(is_numeric($_SESSION['id']))) {

$query = mysql_query("UPDATE session SET time='$ctime2' WHERE userid='".$_SESSION['id']."'") or die('Error');
$affected_rows = mysql_affected_rows();
if ($affected_rows != 1) @session_destroy();
}
}

//many other functions go here

online();
?>

login.php

<?php
include_once 'configuration.inc.php';
include_once 'functions.inc.php';

//many things go here

$upd = mysql_query("INSERT INTO session VALUES ('" . $i['id'] . "','$ctime')") or die('Error2');
Header("Location: /content.php?justlogged=1");
die;
?>

content.php

<?php
include_once 'configuration.inc.php';
include_once 'functions.inc.php';
//many thing go here
echo "content";

?>

test.php

    <?php
    include_once 'configuration.inc.php';
    include_once 'functions.inc.php';

    if (isset($_GET['tid'])&&(is_numeric($_GET['tid']))){
    $result = mysql_query("delete from some_table where something = '" . $_GET['tid'] . "'") or die('Error123a');
Header("Location: /test.php");
    die;
    }

    //file content

    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:25:14+00:00Added an answer on May 26, 2026 at 3:25 pm

    In your function.inc.php you call online() – session time is changed every second. But can it be that you’re switching between pages (login, content, test) more faster than 1 second? In that case time would be the same and you’d get session destroy because of unaffected rows

    Edit:

    Yes. As I thought.

    See how it comes:

    you call login.php: after successful login it creates new session with time X. After this you’re immediately redirected to content.php (time is still X) which calls online again. And of course, as you redirected immediately – time is the same.. so already at point of content.php session is already destroyed, because time wasn’t changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently facing a strange problem in PHP. I have two scripts, index.php which
I have a strange problem where a for loop in PHP only returns the
I have quite a strange problem with PHP and Apache on my local testing
I'm having a strange problem in that I have php inserting text into a
I have a strange problem, I'm sending an SQL query through PHP: INSERT INTO
I see there is strange problem in php with month addition and subtraction. My
I have a strange problem in php MySQL: php connects with 127.0.0.1 but not
I got very strange problem. I have one php website which is running in
Having a really strange problem. Scenario: PHP5.2.9, IIS7, PHP running as FastCGI. I have
I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.