Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用set ID从MySQLi获取数据无效_Php_Mysql_Mysqli - Fatal编程技术网

Php 使用set ID从MySQLi获取数据无效

Php 使用set ID从MySQLi获取数据无效,php,mysql,mysqli,Php,Mysql,Mysqli,知道我做错了什么吗?当我在页面上回显时,我很好地恢复了getID,但并没有从我请求的数据库中设置任何其他内容 我试过一些东西,但似乎无法破解;我想可能是我这边的实际select查询和如何输入getID的标记不好,但可能是错误的 我还添加了一个foreach来列出产品,这可能也是错误的 PHP/HTML include('includes/config.php'); include('header.php'); include('functions.php'); $getID = $_GET['

知道我做错了什么吗?当我在页面上回显时,我很好地恢复了getID,但并没有从我请求的数据库中设置任何其他内容

我试过一些东西,但似乎无法破解;我想可能是我这边的实际select查询和如何输入getID的标记不好,但可能是错误的

我还添加了一个foreach来列出产品,这可能也是错误的

PHP/HTML

include('includes/config.php');
include('header.php');
include('functions.php');

$getID = $_GET['id'];

// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);

// output any connection error
if ($mysqli->connect_error) {
    die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}

// the query
$query = "SELECT i.* 
         FROM invoices as i 
         JOIN customers as c ON c.invoice = ".$getID."
         JOIN invoice_items as p ON p.invoice = ".$getID."
         ORDER BY i.invoice";

// mysqli select query
$results = $mysqli->query($query);

// mysqli select query
if($results) {

    $customer_name = $row['customer_name']; // customer name
    $customer_email = $row['customer_email']; // customer email
    $customer_address_1 = $row['customer_address_1']; // customer address
    $customer_address_2 = $row['customer_address_2']; // customer address
    $customer_town = $row['customer_town']; // customer town
    $customer_county = $row['customer_county']; // customer county
    $customer_postcode = $row['customer_postcode']; // customer postcode
    $customer_phone = $row['customer_phone']; // customer phone number

    //shipping
    $customer_name_ship = $row['customer_name_ship']; // customer name (shipping)
    $customer_address_1_ship = $row['customer_address_1_ship']; // customer address (shipping)
    $customer_address_2_ship = $row['customer_address_2_ship']; // customer address (shipping)
    $customer_town_ship = $row['customer_town_ship']; // customer town (shipping)
    $customer_county_ship = $row['customer_county_ship']; // customer county (shipping)
    $customer_postcode_ship = $row['customer_postcode_ship']; // customer postcode (shipping)

    // invoice details
    $invoice_number = $row['invoice_id']; // invoice number
    $invoice_date = $row['invoice_date']; // invoice date
    $invoice_due_date = $row['invoice_due_date']; // invoice due date
    $invoice_subtotal = $row['invoice_subtotal']; // invoice sub-total
    $invoice_shipping = $row['invoice_shipping']; // invoice shipping amount
    $invoice_discount = $row['invoice_discount']; // invoice discount
    $invoice_vat = $row['invoice_vat']; // invoice vat
    $invoice_total = $row['invoice_total']; // invoice total
    $invoice_notes = $row['invoice_notes']; // Invoice notes
    $invoice_status = $row['invoice_status']; // Invoice status

}

?>

        <h1>Edit Invoice (<?php echo $getID; ?>)</h1>
        <hr>

        <div id="response" class="alert alert-success" style="display:none;">
            <a href="#" class="close" data-dismiss="alert">&times;</a>
            <div class="message"></div>
        </div>

        <form method="post" id="create_invoice">
            <input type="hidden" name="action" value="create_invoice">
            <div class="row">
                <div class="col-xs-5">
                    <h1>
                        <img src="<?php echo COMPANY_LOGO ?>" class="img-responsive">
                    </h1>
                </div>
                <div class="col-xs-7 text-right">
                    <div class="row">
                        <div class="col-xs-9">
                            <h1>INVOICE</h1>
                        </div>
                        <div class="col-xs-3">
                            <select name="invoice_status" id="invoice_status" class="form-control">
                                <option value="open" <?php if($invoice_status == "open"){?>selected<?php } ?>>Open</option>
                                <option value="paid" <?php if($invoice_status == "paid"){?>selected<?php } ?>>Paid</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-xs-4 no-padding-right">
                        <div class="form-group">
                            <div class="input-group date" id="invoice_date">
                                <input type="text" class="form-control required" name="invoice_date" placeholder="Select invoice date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_date; ?>" />
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-4">
                        <div class="form-group">
                            <div class="input-group date" id="invoice_due_date">
                                <input type="text" class="form-control required" name="invoice_due_date" placeholder="Select due date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_due_date; ?>" />
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="input-group col-xs-4 float-right">
                        <span class="input-group-addon">#<?php echo INVOICE_PREFIX ?></span>
                        <input type="text" name="invoice_id" id="invoice_id" class="form-control required" placeholder="Invoice Number" aria-describedby="sizing-addon1" value="<?php echo $getID; ?>">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4>Customer Information</h4>
                            <div class="clear"></div>
                        </div>
                        <div class="panel-body form-group form-group-sm">
                            <div class="row">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom copy-input required" name="customer_name" id="customer_name" placeholder="Enter name" tabindex="1" value="<?php echo $customer_name; ?>">
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom copy-input required" name="customer_address_1" id="customer_address_1" placeholder="Address 1" tabindex="3" value="<?php echo $customer_address_1; ?>">    
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom copy-input required" name="customer_town" id="customer_town" placeholder="Town" tabindex="5" value="<?php echo $customer_town; ?>">        
                                    </div>
                                    <div class="form-group no-margin-bottom">
                                        <input type="text" class="form-control copy-input required" name="customer_postcode" id="customer_postcode" placeholder="Postcode" tabindex="7" value="<?php echo $customer_postcode; ?>">                  
                                    </div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="input-group float-right margin-bottom">
                                        <span class="input-group-addon">@</span>
                                        <input type="email" class="form-control copy-input required" name="customer_email" id="customer_email" placeholder="E-mail address" aria-describedby="sizing-addon1" tabindex="2" value="<?php echo $customer_email; ?>">
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom copy-input" name="customer_address_2" id="customer_address_2" placeholder="Address 2" tabindex="4" value="<?php echo $customer_address_2; ?>">
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom copy-input required" name="customer_county" id="customer_county" placeholder="County" tabindex="6" value="<?php echo $customer_county; ?>">
                                    </div>
                                    <div class="form-group no-margin-bottom">
                                        <input type="text" class="form-control required" name="customer_phone" id="invoice_phone" placeholder="Phone number" tabindex="8" value="<?php echo $customer_phone; ?>">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6 text-right">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4>Shipping Information</h4>
                        </div>
                        <div class="panel-body form-group form-group-sm">
                            <div class="row">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom required" name="customer_name_ship" id="customer_name_ship" placeholder="Enter name" tabindex="9" value="<?php echo $customer_name_ship; ?>">
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom" name="customer_address_2_ship" id="customer_address_2_ship" placeholder="Address 2" tabindex="11" value="<?php echo $customer_address_2_ship; ?>">    
                                    </div>
                                    <div class="form-group no-margin-bottom">
                                        <input type="text" class="form-control required" name="customer_county_ship" id="customer_county_ship" placeholder="County" tabindex="13" value="<?php echo $customer_county_ship; ?>">
                                    </div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom required" name="customer_address_1_ship" id="customer_address_1_ship" placeholder="Address 1" tabindex="10" value="<?php echo $customer_address_1_ship; ?>">
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control margin-bottom required" name="customer_town_ship" id="customer_town_ship" placeholder="Town" tabindex="12" value="<?php echo $customer_town_ship; ?>">                           
                                    </div>
                                    <div class="form-group no-margin-bottom">
                                        <input type="text" class="form-control required" name="customer_postcode_ship" id="customer_postcode_ship" placeholder="Postcode" tabindex="14" value="<?php echo $customer_postcode_ship; ?>">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- / end client details section -->
            <table class="table table-bordered" id="invoice_table">
                <thead>
                    <tr>
                        <th width="500">
                            <h4><a href="#" class="btn btn-success btn-xs add-row"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a> Item</h4>
                        </th>
                        <th>
                            <h4>Qty</h4>
                        </th>
                        <th>
                            <h4>Price</h4>
                        </th>
                        <th width="300">
                            <h4>Discount</h4>
                        </th>
                        <th>
                            <h4>Sub Total</h4>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        foreach($invoice_product as $key => $value) {
                            $item_product = $value;
                            // $item_description = $_POST['invoice_product_desc'][$key];
                            $item_qty = $row['invoice_product_qty'][$key];
                            $item_price = $row['invoice_product_price'][$key];
                            $item_discount = $row['invoice_product_discount'][$key];
                            $item_subtotal = $row['invoice_product_sub'][$key];
                    ?>
                    <tr>
                        <td>
                            <div class="form-group form-group-sm  no-margin-bottom">
                                <a href="#" class="btn btn-danger btn-xs delete-row"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
                                <input type="text" class="form-control form-group-sm item-input invoice_product" name="invoice_product[]" placeholder="Enter item title and / or description" value="<?php echo $item_product; ?>">
                                <p class="item-select">or <a href="#">select an item</a></p>
                            </div>
                        </td>
                        <td class="text-right">
                            <div class="form-group form-group-sm no-margin-bottom">
                                <input type="text" class="form-control calculate" name="invoice_product_qty[]" value="1" value="<?php echo $item_qty; ?>">
                            </div>
                        </td>
                        <td class="text-right">
                            <div class="input-group input-group-sm  no-margin-bottom">
                                <span class="input-group-addon"><?php echo CURRENCY ?></span>
                                <input type="text" class="form-control calculate invoice_product_price required" name="invoice_product_price[]" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $item_price; ?>">
                            </div>
                        </td>
                        <td class="text-right">
                            <div class="form-group form-group-sm  no-margin-bottom">
                                <input type="text" class="form-control calculate" name="invoice_product_discount[]" placeholder="Enter % or value (ex: 10% or 10.50)" value="<?php echo $item_discount; ?>">
                            </div>
                        </td>
                        <td class="text-right">
                            <div class="input-group input-group-sm">
                                <span class="input-group-addon"><?php echo CURRENCY ?></span>
                                <input type="text" class="form-control calculate-sub" name="invoice_product_sub[]" id="invoice_product_sub" value="0.00" aria-describedby="sizing-addon1" value="<?php echo $item_subtotal; ?>" disabled>
                            </div>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <div id="invoice_totals" class="padding-right row text-right">
                <div class="col-xs-6">
                    <div class="input-group form-group-sm textarea no-margin-bottom">
                        <textarea class-"form-control" name="invoice_notes" placeholder="Please enter any order notes here." value="<?php echo $invoice_notes; ?>"></textarea>
                    </div>
                </div>
                <div class="col-xs-6 no-padding-right">
                    <div class="row">
                        <div class="col-xs-3 col-xs-offset-6">
                            <strong>Sub Total:</strong>
                        </div>
                        <div class="col-xs-3">
                            <?php echo CURRENCY ?><span class="invoice-sub-total"> <?php echo $invoice_subtotal; ?></span>
                            <input type="hidden" name="invoice_subtotal" id="invoice_subtotal" value="<?php echo $invoice_subtotal; ?>">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-3 col-xs-offset-6">
                            <strong>Discount:</strong>
                        </div>
                        <div class="col-xs-3">
                            <?php echo CURRENCY ?><span class="invoice-discount"> <?php echo $invoice_discount; ?></span>
                            <input type="hidden" name="invoice_discount" id="invoice_discount" value="<?php echo $invoice_discount; ?>">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-3 col-xs-offset-6">
                            <strong class="shipping">Shipping:</strong>
                        </div>
                        <div class="col-xs-3">
                            <div class="input-group input-group-sm">
                                <span class="input-group-addon"><?php echo CURRENCY ?></span>
                                <input type="text" class="form-control calculate shipping" name="invoice_shipping" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $invoice_shipping; ?>">
                            </div>
                        </div>
                    </div>
                    <?php if (ENABLE_VAT == true) { ?>
                    <div class="row">
                        <div class="col-xs-3 col-xs-offset-6">
                            <strong>TAX/VAT:</strong>
                        </div>
                        <div class="col-xs-3">
                            <?php echo CURRENCY ?><span class="invoice-vat" data-enable-vat="<?php echo ENABLE_VAT ?>" data-vat-rate="<?php echo VAT_RATE ?>" data-vat-method="<?php echo VAT_INCLUDED ?>">0.00</span>
                            <input type="hidden" name="invoice_vat" id="invoice_vat">
                        </div>
                    </div>
                    <?php } ?>
                    <div class="row">
                        <div class="col-xs-3 col-xs-offset-6">
                            <strong>Total:</strong>
                        </div>
                        <div class="col-xs-3">
                            <?php echo CURRENCY ?><span class="invoice-total"> <?php echo $invoice_total; ?></span>
                            <input type="hidden" name="invoice_total" id="invoice_total" value="<?php echo $invoice_total; ?>">
                        </div>
                    </div>
                </div>

            </div>
            <div class="row">
                <div class="col-xs-12 margin-top btn-group">
                    <input type="submit" id="action_edit_invoice" class="btn btn-success float-right" value="Update Invoice" data-loading-text="Updating...">
                </div>
            </div>
        </form>

        <div id="insert" class="modal fade">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Select an item</h4>
              </div>
              <div class="modal-body">
                <?php popProductsList(); ?>
              </div>
              <div class="modal-footer">
                <button type="button" data-dismiss="modal" class="btn btn-primary" id="selected">Add</button>
                <button type="button" data-dismiss="modal" class="btn">Cancel</button>
              </div>
            </div><!-- /.modal-content -->
          </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

<?php
    include('footer.php');
?>
include('includes/config.php');
包括('header.php');
包括('functions.php');
$getID=$\u GET['id'];
//连接到数据库
$mysqli=新的mysqli(数据库\主机、数据库\用户、数据库\通行证、数据库\名称);
//输出任何连接错误
如果($mysqli->connect\u error){
die('Error:('.$mysqli->connect\u errno.')。$mysqli->connect\u Error);
}
//询问
$query=“选择i.*
从我的发票上
在c.invoice=“.getID.”上以c身份加入客户
在p.invoice=“.$getID.”上将发票_项作为p加入
“凭发票订购”;
//mysqli选择查询
$results=$mysqli->query($query);
//mysqli选择查询
如果(结果){
$customer\u name=$row['customer\u name'];//客户名称
$customer\u email=$row['customer\u email'];//客户电子邮件
$customer_address_1=$row['customer_address_1'];//客户地址
$customer_address_2=$row['customer_address_2'];//客户地址
$customer\u town=$row['customer\u town'];//customer town
$customer\u county=$row['customer\u county'];//客户县
$customer\u postcode=$row['customer\u postcode'];//客户邮政编码
$customer\u phone=$row['customer\u phone'];//客户电话号码
//船运
$customer\u name\u ship=$row['customer\u name\u ship'];//客户名称(发货)
$customer_address_1_ship=$row['customer_address_1_ship'];//客户地址(发货)
$customer_address_2_ship=$row['customer_address_2_ship'];//客户地址(配送)
$customer\u town\u ship=$row['customer\u town\u ship'];//customer town(shipping)
$customer_county_ship=$row['customer_county_ship'];//customer county(shipping)
$customer_postcode_ship=$row['customer_postcode_ship'];//客户邮政编码(发货)
//发票明细
$invoice\u number=$row['invoice\u id'];//发票号
$invoice\u date=$row['invoice\u date'];//发票日期
$invoice_due_date=$row['invoice_due_date'];//发票到期日
$invoice_subtotal=$row['invoice_subtotal'];//发票小计
$invoice\u shipping=$row['invoice\u shipping'];//发票发货金额
$invoice\u折扣=$row['invoice\u折扣];//发票折扣
$invoice\u vat=$row['invoice\u vat'];//发票vat
$invoice_total=$row['invoice_total'];//发票总额
$invoice\u notes=$row['invoice\u notes'];//发票备注
$invoice_status=$row['invoice_status'];//发票状态
}
?>
编辑发票()

“class=”img responsive“> 发票 >打开 >支付
查询中的连接有点奇怪,在
ON
子句中有常量

     ...
     JOIN customers as c ON c.invoice = ".$getID."
     JOIN invoice_items as p ON p.invoice = ".$getID."
     ...
您需要这样做。ON子句需要表示三个表中的行之间的关系。将常量值放在这些子句中会失败。请使用
WHERE
子句筛选正确的发票号

   SELECT something, something
     FROM invoices as i 
     JOIN customers as c ON c.invoice = i.invoice
     JOIN invoice_items as p ON p.invoice = i.invoice
    WHERE i.invoice =  ".$getID."
     ORDER BY i.invoice
其次,您确定在这三个表中都有一个名为
invoice
的列吗?您的代码稍后提到了一个名为
invoice\u id
的列。这实际上是您的join列的名称吗

第三,php代码似乎希望三个表中的两个表中的列出现在结果集中

....
$customer_postcode_ship = $row['customer_postcode_ship'];
....
$invoice_number = $row['invoice_id']; 
...
但是您选择了c.*
,它只返回
客户
表中的列

专业提示:避免在
SELECT
子句中使用
*
。相反,列出所需的列。执行以下操作:

SELECT customer_name, customer_email, customer_address_1, customer_address_2,
      customer_town, customer_county, customer_postcode,
      customer_phone, customer_name_ship, customer_address_1_ship,
      customer_address_2_ship, customer_town_ship, customer_county_ship,
      customer_postcode_ship,
      invoice_id, invoice_date, invoice_due_date, invoice_subtotal,
      invoice_shipping, invoice_discount, invoice_vat, invoice_total,
      invoice_notes, invoice_status
 FROM ...
我知道这似乎是不可能的冗长。但这是值得的,因为它允许您的php代码能够适应表结构的变化。它还可以让调试它的程序员清楚地知道结果集中有哪些列

第四,请记住,这里会出现行的组合爆炸。您只筛选一张发票,这很好。可能每个发票只与一个客户相关。这也很好。但是,您的
发票项目
表中的每个匹配行都会重复一次您的客户和发票列值

第五:检查
$mysqli->query($query);
返回的错误


当您使用SQL时,这些东西最终将成为第二天性。不要对正确操作的复杂性感到过分恼火!

Done var_dump($results)和get back NULL-因此可能SELECT查询是错误的-表是发票、客户和发票项-都包含发票(作为ID)回复很好Ollie,我做了很多更改,但我没有运气!我完成了对结果和查询的var_转储,我得到以下信息:“选择客户名称、客户电子邮件、客户地址1、客户地址2、客户镇、客户县、客户邮编、客户电话、客户
$results = $mysqli->query($query);
if (!$results) {
        printf("Errormessage: %s\n", $mysqli->error);
} else {
   /* process the resultset */
}