mysql_fetch_array 有时会失败

发布于 2024-11-02 09:24:30 字数 819 浏览 2 评论 0原文

我正在尝试实现与在线支付框架的连接。

其中一个文件给我带来了一些麻烦,因为有时代码可以工作,有时则不能...我不明白为什么...

这就是代码失败的地方...

$sql = "select transidmerchant,totalamount from nsiapay where     transidmerchant='".$order_number."'and trxstatus='Verified'";
$result = mysql_query($sql);
**$checkout = mysql_fetch_array($result);**
echo "sql : ".$sql;
$hasil=$checkout['transidmerchant'];
echo "hasil: ".$hasil;
$amount=$checkout['totalamount'];
echo "amount: ".$amount;
    // Custom Field
if (!$hasil) {
  echo 'Stop1';
} else {
    if ($status=="Success") {}
}

这只是代码的一部分,但是我认为您尝试查看问题就足够了...它在粗体行上失败,$checkout = mysql_fetch_array($result); 奇怪的是,“echo sql”有效,并且它显示了正确的值,但是当我将它们放在数组中时,有时变量会被传递,有时则不会......所以,当到达 < code>if (!$hasil) 它会失败,因为该值为空...但有时它会起作用...

对可能发生的情况有什么想法吗?

谢 路易斯

I'm trying to implement the connection to a online payment framework.

One of the files is giving me some trouble, because sometimes the code works, sometimes it doesn't... And I can't understand why...

Here's where the code is failing...

$sql = "select transidmerchant,totalamount from nsiapay where     transidmerchant='".$order_number."'and trxstatus='Verified'";
$result = mysql_query($sql);
**$checkout = mysql_fetch_array($result);**
echo "sql : ".$sql;
$hasil=$checkout['transidmerchant'];
echo "hasil: ".$hasil;
$amount=$checkout['totalamount'];
echo "amount: ".$amount;
    // Custom Field
if (!$hasil) {
  echo 'Stop1';
} else {
    if ($status=="Success") {}
}

It's just part of the code but I think it's enough for you to try to see the problem... It fails on the bold line, $checkout = mysql_fetch_array($result);
The weird thing is that the "echo sql" works, and it shows the right values, but then when I put them on the array, sometimes the variables are passed, sometimes they're not... And so, when getting to if (!$hasil) it fails because the value is empty... but sometimes it works...

Any ideas on what might be happen?

Thans
Luis

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£冰雨忧蓝° 2024-11-09 09:24:30

失败的唯一原因是查询不返回任何内容。

正确的方法是检查是否有返回的东西:

$sql = "select transidmerchant,totalamount from nsiapay where     transidmerchant='".$order_number."'and trxstatus='Verified'";
$result = mysql_query($sql);
if($checkout = mysql_fetch_array($result)){
    $hasil = $checkout['transidmerchant'];
    echo "hasil: ".$hasil;
    $amount=$checkout['totalamount'];
    echo "amount: ".$amount;
        // Custom Field
    if (!$hasil) {
      echo 'Stop1';
    } else {
        if ($status=="Success") {}
    }
}else{
    echo "Empty query result";
}

The only way this fail is when query doesn't return anything.

The correct way would be to check if there is something returned:

$sql = "select transidmerchant,totalamount from nsiapay where     transidmerchant='".$order_number."'and trxstatus='Verified'";
$result = mysql_query($sql);
if($checkout = mysql_fetch_array($result)){
    $hasil = $checkout['transidmerchant'];
    echo "hasil: ".$hasil;
    $amount=$checkout['totalamount'];
    echo "amount: ".$amount;
        // Custom Field
    if (!$hasil) {
      echo 'Stop1';
    } else {
        if ($status=="Success") {}
    }
}else{
    echo "Empty query result";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文