数据库未填充


Database not getting populated

我有一个包含两个单选按钮的表单。

类似:

<form class="form-horizontal" name="make_trans" action="<?php echo root; ?>airpay.html" method="post" onsubmit = "return validate();">
	<input type="hidden" id="buyerEmail" name="buyerEmail" value="<?php echo $order['email']; ?>" onkeypress = "changecolor(this.id,'buyerEmailspan')" maxlength = "50"> 
	<input type="hidden" id="buyerPhone" name="buyerPhone" value="<?php echo $order['contact_no']; ?>" onkeypress = "changecolor(this.id,'buyerPhonespan')" maxlength = "15">
	<input type="hidden" id="buyerFirstName" name="buyerFirstName" value="<?php echo $order['first_name']; ?>" onkeypress = "changecolor(this.id,'buyerFirstNamespan')" maxlength = "50">
	<input type="hidden" id="buyerLastName" name="buyerLastName" value="<?php echo $order['last_name']; ?>" onkeypress = "changecolor(this.id,'buyerLastNamespan')" maxlength = "50">
	<input type="hidden" id="buyerAddress" name="buyerAddress" maxlength = "255" value="<?php echo $order['address']; ?>" onkeypress = "changecolor(this.id,'buyerAddressspan')">
	<input type="hidden" id="buyerCity" name="buyerCity" maxlength = "50" value="<?php echo $order['city']; ?>" onkeypress = "changecolor(this.id,'buyerCityspan')">
	<input type="hidden" id="buyerState" name="buyerState" maxlength = "50" value="<?php echo $order['state']; ?>" onkeypress = "changecolor(this.id,'buyerStatespan')">
	<input type="hidden" id="buyerCountry" name="buyerCountry" maxlength = "50" value="<?php echo $order['country']; ?>" onkeypress = "changecolor(this.id,'buyerCountryspan')">
	<input type="hidden" id="buyerPinCode" name="buyerPinCode" maxlength = "8" value="<?php echo $order['pin']; ?>" onkeypress = "changecolor(this.id,'buyerPinCodespan')" >
	<input type="hidden" id="orderid" name="orderid" value="<?php echo $order['order_no']; ?>" onkeypress = "changecolor(this.id,'orderidspan')">
	<input type="hidden" id="amount" name="amount" value="<?php echo number_format($order['totalAmt'],2,'.',''); ?>" onkeypress = "changecolor(this.id,'amountspan')">
	
	<center>
		<div class="form-group">
			<label class="label-checkbox">
				<input type="radio" name = "delivery_options" id = "cod" value = "cod">
				Cash On Delivery
			</label>&nbsp;&nbsp;&nbsp;
			<label class="label-checkbox">
				<input type="radio" name = "delivery_options" id = "pay_now" value = "pay_now">
				Pay Now
			</label>
			<?php
				if (($_SERVER['REQUEST_METHOD'] === 'POST ') && (isset($_POST['submit'])))
					{
						if ($_POST['delivery_options'] == "cod")
							{
								$payment_mode = "COD";
							}
						else ($_POST['delivery_options'] == "pay_now")
							{
								header('Location: http://localhost/ovenfresh/airpay.html');
							}
					}
				?>
		</div>
	</center>
	<center>
        <p style="font-family:Arial, Helvetica, sans-serif; font-size:16px;">Your Order No is # <?php echo $order['order_no']; ?> and Billing Amount is <?php echo number_format($order['totalAmt'],2); ?></p>    
        <div>
            <button type="submit" class="btn btn-success">Submit</button>
		</div>
	</center>
</form>

现在,在选择"货到付款"时,必须执行一个插入查询,并在选择"立即付款"时重定向到另一个页面。

我试过了。除payment_mode外,所有其他字段都已填充

数据库查询:

$order = array('customer_id'    =>  $customer_id,
                   'subtotal'   =>  $_POST['subtotal'],
                   'totalAmt'   =>  $_POST['totalAmt'],
                   'dileveryAmt'    =>  $_POST['dileveryAmt'],
                   'date'   =>  date('Y-m-d'),
                  'midnightdelivery'    =>  $_POST['midnightdelivery'],
                  'delivery_date'   =>  $_POST['delivery_date'],
                  'message_on_cake' =>  $_POST['message_on_cake'],
                  'special_instruction' =>  $_POST['special_instruction'],
                  'payment_mode'    =>  $_POST['payment_mode']
                  );
    $order_id = $this->db->insert('orders',$order);

function insert($table=null,$array_of_values=array()) {
    if ($table===null || empty($array_of_values) || !is_array($array_of_values)) return false;
    $fields=array(); $values=array();
    foreach ($array_of_values as $id => $value) {
        $fields[]=$id;
        if (is_array($value) && !empty($value[0])) $values[]=$value[0];
        else $values[]="'".mysql_real_escape_string($value,$this->con)."'";
    }
    $s = "INSERT INTO $table (".implode(',',$fields).') VALUES ('.implode(',',$values).')';
    if (mysql_query($s,$this->con)) return mysql_insert_id($this->con);
    return false;
}

您检查的短语错误,请删除空格

if (($_SERVER['REQUEST_METHOD'] === 'POST ')&& (isset($_POST['submit'])))

进入

if (($_SERVER['REQUEST_METHOD'] === 'POST') && (isset($_POST['submit'])))

还有更多的错误,比如按钮标签中的双class。请仔细检查您的代码。

我可以看出您的代码可能无法正常工作的两个原因。第一个是你在这里的比较:

if(($_SERVER['REQUEST_METHOD']==='POST')&amp;(isset($_POST[‘submit’]))

应更改为:

if(($_SERVER['REQUEST_METHOD']==='POST')&amp;(isset($_POST[‘submit’]))

我所做的只是删除字符串文字中的空格,将其从"POST"更改为"POST"(尾部空格表示两者不相等)。此外,我认为$_POST中的键"submit"也没有设置,因为您还没有为提交按钮设置名称。所以你也应该改变:

<button type="submit"class="btn-btn-success">提交<按钮>

<button name="submit"type="submit"class="btn-btn-success">提交<按钮>

我所做的更改是添加了值为"submit"的属性"name"。

其次,在你的第二段代码中,下面这一行可能是罪魁祸首:

"payment_mode"=>$_POST["payment_mode"]

$_POST中没有定义这样的键("payment_mode")(仅根据您提供的代码判断)。支付模式存储在关键字"delivery_options"中,稍后存储在变量$payment_mode中。

因此,可以通过更改以下行来解决问题:

"payment_mode"=>$_POST["payment_mode"]

"payment_mode"=>$_POST["delivery_options"]

'payment_mode'=>$payment_mode

Hm,您没有发布完整的代码,所以这很难,但正如我所看到的,原因不是保存,因为$_POST['payment_mode']没有在任何地方定义,但您将其存储在一个变量中。

所以改变这条线

 'payment_mode'    =>  $_POST['payment_mode']

到此

'payment_mode'    =>  $payment_mode 

进行两次更改

1.if (($_SERVER['REQUEST_METHOD'] === 'POST ') && (isset($_POST['submit'])))

更改为

if (($_SERVER['REQUEST_METHOD'] === 'POST') && (isset($_POST['submit'])))

  1. <button type="submit" class="btn btn-success">Submit</button>

更改为

<button type="submit" name="submit" class="btn btn-success">Submit</button>