我在我的代码中找不到错误,我总是没有足够的资金 [英] I cant find the error in my code I always get insufficient funds

查看:85
本文介绍了我在我的代码中找不到错误,我总是没有足够的资金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了3个sql表:"client","inv"和"wit" 数据库连接和代码中的其他页面都可以正常工作,但是此特定页面存在问题.

I have 3 sql tables set up: 'client' 'inv' and 'wit' Database connection works fine and other pages in the code, but I'm having issues with this particular page.

我有一个页面new.php:

I have a page new.php:

<?php session_start();
if(!isset($_SESSION["email"]))
{
    header("location:../login.php");
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">

<head></head>
<body>
<?php include("header.php"); ?>
<form action="withdraw.php" method="post" class="m-form m-form--label-align-right m-form--fit" id="withdrawalForm">
<input type="hidden" name="email" value="<?php echo $userVal['email']; ?>" />
<input type="hidden" name="w_date" value="<?php echo date("d-m-Y"); ?>" />
<input type="hidden" name="w_status" value="Pending" />
<input type="hidden" name="balance" value="<?php echo $userVal['balance']; ?>" />
<input type="text" name="method" value="" />
<input type="text" name="balance" value="$<?php echo $userVal['balance']; ?>" disabled=true readonly />
<input type="number" name="w_amount" value="" placeholder="<?php echo $userVal['balance']; ?> or less" required />
<input type="text" name="wallet" value="" placeholder="Wallet Address" required />
<input type="submit" name="withdraw" value="withdraw" />
</body>
</html>

header.php具有:

The header.php has:

<?php
include("pdoconnect.php");

$id = $_SESSION["email"];
$user = $pdotestconn->prepare("SELECT * FROM client JOIN inv ON client.email = inv.email WHERE client.email = :uname ");
$user->bindParam(":uname", $id);
$user->execute();
$userVal = $user->fetch(PDO::FETCH_ASSOC);

然后我有了withdraw.php:

Then I have the withdraw.php:

<?php

include("pdoconnect.php");

$datei=date("D M d, Y g:i a"); 
$email = $_POST['email'];
$wdate = $_POST['w_date'];
$method = $_POST['method'];
$wamount = $_POST['w_amount'];
$wstatus = $_POST['w_status'];
$wallet = $_POST['wallet'];

$user = $pdotestconn->prepare("SELECT * FROM client JOIN wit ON client.email = wit.email WHERE client.email = :uname ");
$user->bindParam(":uname", $email);
$user->execute();
$userVal = $user->fetch(PDO::FETCH_ASSOC);

if ($wamount >= $userVal['balance']) {
        echo "Insufficient Fund";
    } else {
        $balance = $userVal['balance'] - $wamount;

        $ins = $pdotestconn->prepare("INSERT INTO wit (email,w_date,method,w_amount,w_status,wallet) VALUES (:email,:w_date,:method,:w_amount,:w_status,:wallet)");
        $ins->bindParam(":email", $email);

        $ins->bindParam(":w_date", $wdate);
        $ins->bindParam(":method", $method);
        $ins->bindParam(":w_amount", $wamount);
        $ins->bindParam(":w_status", $wstatus);
        $ins->bindParam(":wallet", $wallet);
        $ins->execute();

        $up = $pdotestconn->prepare("UPDATE client SET balance = :credit WHERE email = :email ");
        $up->bindParam(":credit", $balance);
        $up->bindParam(":email", $email);
        $up->execute();
        echo "ok";
    }
?>

每次我尝试提款时,都会收到"资金不足",但那里有足够的资金.

Every time I try to do the withdraw, I get "Insufficient Funds" but I have enough funds there.

推荐答案

如果您的代码执行了意外的操作,则很有可能在某个地方进行假设.您可以确定的一件事是,如果代码中显示资金不足",则它会看到$wamount的值大于或等于$userVal['balance']的值.

If your code is doing something unexpected, there's a good chance you're making an assumption somewhere. One thing you can be certain of in your code is that if it's printing "Insufficient Fund" then it sees the value of $wamount as greater than or equal to that of $userVal['balance'].

这可能是由于以下两个原因造成的,其中包括余额不如您想像的多,或者有可能存在某种强制性或类型差异或不正确的字段映射.

This could be because of a couple of reasons, including that the balance isn't as much as you thought, or just as likely, there's some sort of coercion or type difference or incorrect field mapping going on.

我的建议是在if语句之前查看那些值.如果您有调试器并且知道如何使用它,请执行此操作.但是,如果您不这样做,则可以在if语句之前临时添加此代码.

My recommendation would be to take a look at those values before the if statement. If you have a debugger and know how to use it, do that. But if you don't you could temporarily add this code right before the if statement.

var_dump('Withdrawal amount', $wamount);
var_dump('Balance', $userVal['balance']);

这应该会导致一些输出,告诉您变量$wamount$userVal['balance']的值以及类型.看一下您获得的值.希望这个问题会很明显.如果不是,请特别注意变量的类型.如果它们不同,例如其中一个是字符串,另一个是浮点数或int等,则PHP正在执行类型强制,并且您可能不知道该继续进行哪些操作,这将导致看起来像值达到您的期望,但实际上不是.

This should result in a bit of output that tells you the values and also the types of the variables $wamount and $userVal['balance']. Take a look at the values you get. Hopefully the issue will be obvious. If not, pay extra special attention to the types of the variables. If they are different, as in one is a string and the other is a float or an int or something, PHP is doing type coercion and there's possibly something you're not aware of going on with the that which will result in values that seem to be what you expect, but are really not.

这篇关于我在我的代码中找不到错误,我总是没有足够的资金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆