Why is this not adding?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try this:

Code: Select all

<?php
/**
 * EVERAH | I added this bit for error checking and repoting
 */
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);

/**
 * EVERAH | I added the following for debugging
 */
$debug = true; // set to false to turn off

include 'dbcon.php';
include 'func.php';
require_once 'auth.php';
require_once 'includes/defines.php';

if (!isLoggedIn()) {
    Redirect('index.php');
}

if ($debug) {
    echo '<p>Debug: SESSION sess_name is : ' . $_SESSION['sess_name'] . ' at ' . __LINE__ . '</p>';
}
$log = $_SESSION['sess_name'];

if ($debug) {
    echo '<p>Debug: Variable $s is : ' . $s . ' at ' . __LINE__ . '</p>';
}
$res3 = mysql_query("Select id,echo_count FROM userdata WHERE id='$s'") or die( mysql_error() );
$sel = mysql_fetch_row($res3);
if ($debug) {
    echo '<p>Debug: Variable $sel is : ' . $sel . ' at ' . __LINE__ . '</p>';
}

mysql_free_result($res3);

if ($debug) {
    echo '<p>Debug: Variable $p is : ' . $p . '</p>';
    echo '<p>Debug: SESSION echos is: ' . $_SESSION['echos'] . ' at ' . __LINE__ . '</p>';
}

if ($_SESSION['echos'] >= $p) {
    $echos -= $p;
    $_SESSION['echos'] = $echos;

    if ($debug) {
        echo '<p>Debug: Variable $log is : ' . $log . ' at ' . __LINE__ . '</p>';
    }

    mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") or die(mysql_error());
   
    $echosseller += $p;
    $sel[1] = $echosseller;
    if ($debug) {
        echo '<p>Debug: Variable $s is : ' . $s . ' at ' . __LINE__ . '</p>';
    }
    mysql_query("UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ") or die(mysql_error());
   
    if ($debug) {
        echo '<p>Debug: Variable $log is : ' . $log . ' at ' . __LINE__ . '</p>';
        echo '<p>Debug: Variable $it is : ' . $it . ' at ' . __LINE__ . '</p>';
        echo '<p>Debug: Variable $pr is : ' . $pr . ' at ' . __LINE__ . '</p>';
    }

    mysql_query("INSERT INTO coll_inven (user,item,price) VALUES ( '$log', '$it', '$pr' )");
    mysql_query("DELETE FROM coll_sell WHERE id=$id");

    header('Location: vendor_grovepark.php');
    exit;
} else {
    header('Location: vendor_grovepark.php?alert=noechos');
    exit;
}
?>
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post by beloveddoll »

I got the adding to work but in doing so I found another problem.

If the $s person is logged in while the transaction is taken place, their echos count is not being displayed. They would have to log out then back in, in order to get that echos that was put into their database. That`s a session problem, right?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Where in the app does the user $s have their echos displayed?
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post by beloveddoll »

It gets displayed when the person of $s is logged in.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

beloveddoll wrote:I got the adding to work but in doing so I found another problem.

If the $s person is logged in while the transaction is taken place, their echos count is not being displayed. They would have to log out then back in, in order to get that echos that was put into their database. That`s a session problem, right?
Sorry, I must have misunderstood you. If you are updating data in a database for a user, it makes no difference when the update takes place in relation to a user being logged in. It will matter if that value is stored in a session/cookie variable that is not updated. But if it is in the database, then as soon as it is updated it becomes available to call again (though you could always increment it in the dataset instead of making another call to the database).
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post by beloveddoll »

It is added to the database. What`s making this even stranger is that if the logged in person gets echos from, say, commenting on a submitted picture, the change is visible. But if someone were to purchase an item from them, the change is not seen.

However in both cases, when the change is made to the database, the database shows it. It`s just that in one case the logged in person doesn`t have to log out to see the changes, whereas the other case they do have to log out and then back in.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This might be an issue of timing, as in where in the script the update is made in relation to where you are noticing the no change.
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post by beloveddoll »

How do we find out for sure?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Debug. Add notices in the script to track where things are taking place (if you cannot look at the code and see it).
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post by beloveddoll »

Ok, I haven`t worked with debug much except for copying what people put in for me to put in. Maybe if you can brief me on how to use debug I can go around with it in my files and see what turns up.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

See what I did in the script snippet I posted earlier in this thread? Do that at various points along the way.
Post Reply