Jump to content

Subtract from one table, add to the other table?


djfox

Recommended Posts

Sorry to keep bothering but I`m still learning about php.

 

<?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());

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

}

header("Location: vendor_grovepark.php");

else {
header("Location: vendor_grovepark.php?alert=noechos");
}
?>

 

I know the code is incomplete. I`m stumped with something.

 

I have in there to take currency (echos) from the echo_count of the logged in person buying the item. How do I add this number to the seller? I have in the query to call on the seller`s info, but how do I get $p added to the seller`s echos?

 

I`m basically looking for $p added to $sel[1] a simple math thing to add $p to whatever number is already in $sel[1]

Link to comment
Share on other sites

Just because I made a bit of changes to the original code and the system won`t let me edit the original post:

 

<?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());

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");
}
?>

 

But I still can`t figure out how to add $p tp $sel[1]

Link to comment
Share on other sites

$p is the value that will be added. It will be a different value depending on the value the page before it indicates:

<a href="sell_coll.php?id=<? echo "$row[0]" ?>&p=<? echo "$row[3]" ?>&pr=<? echo "$row[4]" ?>&s=<? echo "$row[5]" ?>&it=<? echo "$item[0]" ?>">Buy</a>

 

The codes I posted earlier are from the sell_coll.php file.

Link to comment
Share on other sites

I know this is being posted several times but reading over my code again, I found a couple errors and got them sorted out, here is the final revised code:

 

<?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());

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");
}
?>

 

But still need to be able to add $p to $sel[1]

I`m totally stumped.

Link to comment
Share on other sites

Ok, trying to explain it as best as I can.

 

Person A puts Item A into the market to sell. Person A sets Item A`s sellprice to 75 echos. Person B comes along and decides they want to buy Item A. So they click the link that does the transaction. The transaction is that the 75 echos is taken from Person B`s echo_count and entered into Person A`s echo_count. Item A is taken from Person A`s inventory and put into Person B`s inventory.

 

My code has all those parts working except putting the echos into Person A`s echo_count.

Link to comment
Share on other sites

That`s what I`m having trouble with. I`m not sure of how the code should be since some instances are different fro the code for Person B.

 

I can easily modify this part of the code:

mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ")

 

But for this part:

$_SESSION['echos'] = $echos = $echos - $p;

 

How do I manipulate that to work for Person A (who is $s )?

Link to comment
Share on other sites

whats hard with that

 

$_SESSION['echos'] = $echos = $echos - $p;

  mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ");//sample1

  mysql_query("UPDATE userdata SET echo_count = (value here +$echos) WHERE login = '".$log."' ");//sample

 

or maybe

mysql_query("UPDATE userdata SET echo_count+$value WHERE login = '".$log."' ");//sample

Link to comment
Share on other sites

The current echo count code is for Person B (the buyer or $log):

$_SESSION['echos'] = $echos = $echos - $p;
   mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ")

 

The code would need to change to add the echo amount ($p) to the seller`s ($s) echo_count

$_SESSION['echos'] = $echos = $echos + $p;
   mysql_query("UPDATE userdata SET echo_count = $echos WHERE id = '$s' ")

 

But it`s that $_SESSION['echos'] = $echos = $echos part that needs to change.

 

$_SESSION['echos'] = $echos = $echos

takes the echos of the buyer and adds to what`s already there.

I don`t know how to change it completely to add to $s echo_count.

It can`t have $echos (I`m assuming) because then it would just copy what echos the buyer has. That would not be right because both persons would have different values in their echo_count.

It can`t have the $_SESSION thing because that is for the buyer, not the seller.

 

Only analogy I can think of is if you ever played Gaia Online and used their marketplace. It`s basic retail-consumer functions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.