PHP Query减法不起作用

时间:2018-04-19 17:05:18

标签: php mysql

您好我试图在交易后减去用户信用额度,但更新时出现问题。测试accepted_bidder = 15且客户信用额度为100.出于某种原因,我更新时为-15而不是75知道为什么会这样吗?

输出:警告:mysqli_fetch_array()要求参数1为mysqli_result,第20行的C:\ xampp \ htdocs \ payment2.php中给出的数组

注意:未定义的变量:第26行的C:\ xampp \ htdocs \ payment2.php中的信用

<?php
session_start();
require 'config.php';


$id = $_SESSION['login_user'];
$jobid    = $_POST['job_id'];
$poster_id    = $_POST['poster_id'];
$accepted_bidder    = $_POST['accepted_bidder'];
$accepted_bid    = (int) $_POST['accepted_bid'];
$poster_id = $_POST['poster_id'];

$query = "SELECT credit FROM `customer` WHERE email_adress = '$id'";

$success = $conn->query($query);


$result = mysqli_fetch_array($success);

while($row = mysqli_fetch_array($result)):
$credit = (int)$row['credit'];
endwhile;

//var_dump($result);
//var_dump($accepted_bid); 
$updated_credit = $credit - $accepted_bid;
//echo $updated_credit;


$query2   = "UPDATE job SET start_escrow = '1' WHERE job_id = '$jobid'";
$success2 = $conn->query($query2);

$query3   = " UPDATE customer SET credit = '$updated_credit' WHERE email_adress = '$id'";
$success3 = $conn->query($query3);



if (!$success) {
    die("Couldn't enter data: ".$conn->error);

}

echo "Thank You For Contacting Us <br>";
 //header("location: myjobs.php");



$conn->close();




?>

1 个答案:

答案 0 :(得分:3)

$result = mysqli_fetch_array($success); 不是查询的结果,它是您使用的第一行:

while ($row = mysqli_fetch_array($result))

所以当你这样做的时候:

$success = $conn->query($query);
$result = mysqli_fetch_array($success);

您尝试将该行用作查询结果。

替换这两行:

$result = $conn->query($query);

from PySide.QtGui import *
from PySide.QtCore import *

class MyModel(QStandardItemModel):

    def __init__(self):
        super(MyModel, self).__init__()
        iroot = self.invisibleRootItem()

        self.setHorizontalHeaderLabels(['Name', 'Interpolation', 'Normalize'])

    def newTopLevelItem(self, name = 'myTopLevelItem'):
        item = ItemTypeA(name)
        root_item = self.invisibleRootItem()
        root_item.appendRow([item]+item.settingItems())
        return item


class ItemTypeA(QStandardItem):
    def __init__(self, *args, **kwargs):
        super(ItemTypeA, self).__init__(*args, **kwargs)

        self.s_interpolation =QStandardItem('0')
        self.s_normalize = QStandardItem('False')

    def settingItems(self):
        return [
            self.s_interpolation,
            self.s_normalize
        ]

    def newChildItem(self, name = 'newChildItem'):
        childItem = ItemTypeB( name )
        self.appendRow( [childItem]+childItem.settingItems() )


class ItemTypeB(QStandardItem):
    def __init__(self, *args, **kwargs):
        super(ItemTypeB, self).__init__(*args, **kwargs)

        self.s_multiply = QStandardItem('1.0')

    def settingItems(self):
        return [
            self.s_multiply,
        ]


class TreeViewA(QTreeView):
    '''
    THIS VIEW Needs the Headers:
        Item Name | Interpolation | Normalize
    '''
    def __init__(self):
        super(TreeViewA, self).__init__()
        model = MyModel()
        self.setModel(model)

        newItem = model.newTopLevelItem()
        newItem.newChildItem()

class TreeViewB(QTreeView):
    '''
    THIS VIEW Needs the Headers:
        Item Name | Multiply
    '''
    def __init__(self, sourceView):
        super(TreeViewB, self).__init__()
        model = sourceView.model()
        self.setModel(model)
        self.setRootIndex(model.index(0,0))


class MyWidget(QWidget):

    def __init__(self):
        super(MyWidget, self).__init__()
        layout = QHBoxLayout()
        viewA = TreeViewA()
        viewB = TreeViewB(viewA)
        layout.addWidget(viewA)
        layout.addWidget(viewB)
        self.setLayout(layout)

widget = MyWidget()
widget.show()