Abel1216 Posted July 11, 2020 Share Posted July 11, 2020 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted July 11, 2020 Share Posted July 11, 2020 When you get a keyboard that adds indenting and line breaks I'll read your code. 1 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 11, 2020 Share Posted July 11, 2020 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. Quote Link to comment Share on other sites More sharing options...
Abel1216 Posted July 16, 2020 Author Share Posted July 16, 2020 Thanks. I have fixed it since... @mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.