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

beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Why is this not adding?

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post 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:

Code: Select all

?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

you have to close the

Code: Select all

else {
statement in the last line
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post by beloveddoll »

I get the same thing.
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Obviously $echosseller has no value at all.
Where do you assign a value to $echosseller prior to $sel[1] = $echosseller = $echosseller + $p;?
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post 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.
Post Reply