Hello i need little help overhere im confuzed getting user data from mysql database i want to update the payCheck
column in the database but that column is located in the receiver
or where (in the code)
field i have this code please someone help me...
<?php
require 'connect.php';
require 'header.php';
if(isset($_POST['howMuch']) && isset($_POST['where'])) {
$howMuch = $_POST['howMuch'];
$where = $_POST['where']; // this is the receiver
if(!empty($howMuch) || !empty($where)) {
$user_mBalance = getUserData('payCheck'); // getting already logged user field 'payCheck'
if($howMuch > $user_mBalance) {
echo "<br><br><br><br><br>You cannot donate more than you have!";
} else {
$query = "SELECT `ID` FROM `users` WHERE `First Name`='".mysql_real_escape_string($where)."'";
if($query_run = mysql_query($query)) {
$query_num_rows = mysql_num_rows($query_run);
if($query_num_rows == 0) {
echo "<br><br><br>Username doesn't exist.";
} else if($query_num_rows == 1) {
$sender = getUserData('First Name'); // getting already logged user field 'First Name'
$total = $user_mBalance - $howMuch; // calculations of loged user 'payCheck' + 'howMuch'
$query = "UPDATE `users` SET `payCheck`='$total' WHERE `First Name`='$sender'"; // updating the sender `payCheck` field
$query_run = mysql_query($query);
echo "<br><br><br>You have donated $howMuch to $where";
}
}
}
} else {
echo "You can't leave empty!";
}
}
?>
So simply i just want to get the receiver payCheck
balance and than to add the money which sender sended to him something like $total = $receiver_moneyBalance + $howMuch;
And also here is the code for getUserData();
function loggedin() {
if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
return true;
} else {
return false;
}
}
function getUserData($field) {
$query = "SELECT `$field` FROM `users` WHERE `ID`='".$_SESSION['user_id']."'";
if($query_run = mysql_query($query)) {
if($query_result = mysql_result($query_run, 0, $field)) {
return $query_result;
}
}
}