Jump to content

Greater than logic issues


Abel1216

Recommended Posts

I wrote a code to echo "limit reached" if A is greater than B. But if A is 400030 and B is 400000 it shows no output. If A is further greater than that, let say 400060 or any number higher than that, it shows the output.. Please how do I explain that? The code snippet to demonstrate what I mean is....

 

 

 

 

 


 

<?php include_once('db.php'); error_reporting(E_ALL | E_WARNING | E_NOTICE); ini_set('display_errors', TRUE);

if (session_status() == PHP_SESSION_NONE)

{

session_start();

}

if(!isset($_SESSION['login']))

{

echo ("<script>location.href='../clogin/'</script>");

die();

}

if(isset($_POST['transfer']))

{

$username = $_SESSION['login']; $transAmount = $_POST['transAmount']; $totalTrans = $transAmount + 30; $sql = "SELECT * FROM customer WHERE username = ?";

$stmt = $connection->prepare($sql);

$stmt->bind_param('s', $username);

$stmt->execute();

$result = $stmt->get_result(); if(!$result)

{

die('ERROR:' . mysqli_error($connection));

}

$count = $result->num_rows; if($count == 1)

{

while ($row = $result->fetch_assoc())

{

$accTrans = $totalTrans + $row['dailyTrans'];

$sql2 = "UPDATE customer set dailyTrans=? WHERE username=?"; $stmt = $connection->prepare($sql2); $stmt->bind_param('is', $accTrans,$username);

$stmt->execute(); if(!$stmt)

{

die('network problem');

}

if($row['dailyTrans'] >= $row['dailyLimit'])

{

echo '<script>swal.fire("FAILED!!", "<strong>You have reached the total amount you can send per day.</strong><hr><br/><i>Visit your bank to increase transfer limit.</i>", "error"); window.setTimeout(function(){ window.location.href = "transfer1.php";} , 1700); </script>'; //exit();

}

else {

echo"";

}

}//while loop

}//count

}//submit

?>


 

 

 

My question Summary Again

The value for $row['dailyTrans'] is 400030 and the value of $row['dailyLimit'] is 400000

This is suppose to echo out the error but fails... if $row['dailyTrans'] is greater than 400030, it echoes out. What is the logic behind that?.

Please be nice with your comments as usual. Thanks . Both Value are integers!! . The code works well just that at 400030 it doesn't output that its greater than 400000

 

Link to comment
Share on other sites

what does var_dump($row); show?

btw - you should INSERT a new row for every transaction that affects a user's account balance, not update the value in a column. you currently don't have an 'audit trail' to detect if a programming mistake, duplicate form submission, or nefarious activity has altered the value. your current code will also update the value to the wrong amount if there are concurrent instances of your script being executed since the 'last' update query to get executed will replace any previously updated value.

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.