Page 1 of 2
Why is this not adding?
Posted: Tue Jul 17, 2007 8:17 am
by beloveddoll
Code: Select all
<?php
include("dbcon.php");
include("func.php");
require_once "auth.php";
require_once "includes/defines.php";
if (!isLoggedIn()) {
Redirect("index.php");
}
$log = $_SESSION['sess_name'];
$res3 = mysql_query("Select id,echo_count FROM userdata WHERE id='$s'")or die( mysql_error() );
$sel = mysql_fetch_row($res3);
mysql_free_result($res3);
if ($_SESSION['echos'] >= $p) {
$_SESSION['echos'] = $echos = $echos - $p;
mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") or die(mysql_error());
$sel[1] = $echosseller = $echosseller + $p;
mysql_query("UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ") or die(mysql_error());
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");
}
else {
header("Location: vendor_grovepark.php?alert=noechos");
}
?>
I want $p added to the current value of $sel[1]
But the codes is not adding to it. Everything else in the code is working fine except for that one part. I`ve been trying to figure it out for about 6 hours now.
Posted: Tue Jul 17, 2007 8:26 am
by volka
please try
Code: Select all
echo '<div>Debug p: ', $p, "</div>\n";
if ($_SESSION['echos'] >= $p) {
$_SESSION['echos'] = $echos = $echos - $p;
$query = "UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ";
echo "<div>Debug: ", $query, "</div>\n";
mysql_query($query) or die(mysql_error());
$sel[1] = $echosseller = $echosseller + $p;
$query = "UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ";
echo "<div>Debug: ", $query, "</div>\n";
mysql_query($query) or die(mysql_error());
mysql_query("INSERT INTO coll_inven (user,item,price) VALUES ( '$log', '$it', '$pr' )");
mysql_query("DELETE FROM coll_sell WHERE id=$id");
die();
header("Location: vendor_grovepark.php");
}
else {
and post the output.
Posted: Tue Jul 17, 2007 8:36 am
by beloveddoll
Output:
Blank page with this message:
Parse error: syntax error, unexpected $end in /home/secrett1/public_html/testing/sell_coll.php on line 57
Line 57:
Posted: Tue Jul 17, 2007 8:42 am
by volka
You have to insert my code snippet where it fits.
Search for
if ($_SESSION['echos'] >= $p) {
and
else {
in both your and my code snipped and then merge the scripts accordingly.
Posted: Tue Jul 17, 2007 8:43 am
by arturm
you have to close the
statement in the last line
Posted: Tue Jul 17, 2007 8:49 am
by beloveddoll
I get the same thing.
Posted: Tue Jul 17, 2007 8:59 am
by beloveddoll
I know that these lines
Code: Select all
$sel[1] = $echosseller = $echosseller + $p;
mysql_query("UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ") or die(mysql_error());
there`s something in them that`s keeping it from adding.
Posted: Tue Jul 17, 2007 9:12 am
by volka
Ok, I give up, complete script for cvopy&paste
Code: Select all
<?php
include("dbcon.php");
include("func.php");
require_once "auth.php";
require_once "includes/defines.php";
if (!isLoggedIn()) {
Redirect("index.php");
}
$log = $_SESSION['sess_name'];
$res3 = mysql_query("Select id,echo_count FROM userdata WHERE id='$s'")or die( mysql_error() );
$sel = mysql_fetch_row($res3);
mysql_free_result($res3);
echo '<div>Debug p: ', $p, "</div>\n";
if ($_SESSION['echos'] >= $p) {
$_SESSION['echos'] = $echos = $echos - $p;
$query = "UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ";
echo "<div>Debug: ", $query, "</div>\n";
mysql_query($query) or die(mysql_error());
$sel[1] = $echosseller = $echosseller + $p;
$query = "UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ";
echo "<div>Debug: ", $query, "</div>\n";
mysql_query($query) or die(mysql_error());
mysql_query("INSERT INTO coll_inven (user,item,price) VALUES ( '$log', '$it', '$pr' )");
mysql_query("DELETE FROM coll_sell WHERE id=$id");
die();
header("Location: vendor_grovepark.php");
}
else {
header("Location: vendor_grovepark.php?alert=noechos");
}
?>
what does that print?
Posted: Tue Jul 17, 2007 9:20 am
by beloveddoll
Debug p: 10
Debug: UPDATE userdata SET echo_count = 970 WHERE login = 'Beloved Doll Lit'
Debug: UPDATE userdata SET echo_count = 10 WHERE id = '97'
It wiped out the seller`s echos from 375 to 10.
It should`ve made the echo_count go from 375 to 385 because the $p (in this case 10) should`ve been added to what`s already there.
Posted: Tue Jul 17, 2007 9:36 am
by volka
more debug code
Code: Select all
echo 'echosseller: ', $echosseller, "<br />\n";
echo 'p: ', $p, "<br />\n";
$sel[1] = $echosseller = $echosseller + $p;
echo 'echosseller: ', $echosseller, "<br />\n";
$query = "UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ";
echo "<div>Debug: ", $query, "</div>\n";
Posted: Tue Jul 17, 2007 9:43 am
by beloveddoll
Debug p: 10
Debug: UPDATE userdata SET echo_count = 930 WHERE login = 'Beloved Doll Lit'
echosseller:
p: 10
echosseller: 10
Debug: UPDATE userdata SET echo_count = 10 WHERE id = '97'
echo_count should`ve been 24
Posted: Tue Jul 17, 2007 9:48 am
by volka
Obviously $echosseller has no value at all.
Where do you assign a value to $echosseller prior to $sel[1] = $echosseller = $echosseller + $p;?
Posted: Tue Jul 17, 2007 9:55 am
by beloveddoll
I basically manipulated what someone else had put for subtracting echos to the logged in person:
Code: Select all
$_SESSION['echos'] = $echos = $echos - $p;
mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") or die(mysql_error());
So I made:
Code: Select all
$sel[1] = $echosseller = $echosseller + $p;
mysql_query("UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ") or die(mysql_error());
So $echoseeller should`ve been the value of $sel[1]
Code: Select all
$res3 = mysql_query("Select id,echo_count FROM userdata WHERE id='$s'")or die( mysql_error() );
$sel = mysql_fetch_row($res3);
mysql_free_result($res3);
$sel[1] should be the echo_count value
It looks like it`s calling the $s just fine.
Posted: Tue Jul 17, 2007 10:07 am
by volka
beloveddoll wrote:I basically manipulated what someone else had put for subtracting echos to the logged in person:
Can you ask that person?
Posted: Tue Jul 17, 2007 10:09 am
by beloveddoll
volka wrote:beloveddoll wrote:I basically manipulated what someone else had put for subtracting echos to the logged in person:
Can you ask that person?
I lost contact with that person, which is why I`m trying to do this myself. I changed the code to:
Code: Select all
$echosseller = $sel[1] + $p;
mysql_query("UPDATE userdata SET echo_count = $echosseller WHERE id = '$s' ") or die(mysql_error());
And it`s still not adding.