数据库未填充

时间:2015-02-19 11:50:28

标签: php html mysql

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

喜欢:

<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;
}

4 个答案:

答案 0 :(得分:2)

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

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

进入

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

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

答案 1 :(得分:2)

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

  

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

应改为:

  

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

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

  

&lt; button type =“submit”class =“btn btn-success”&gt;提交&lt; / button&gt;

  

&lt; button name =“submit”type =“submit”class =“btn btn-success”&gt;提交&lt; / button&gt;

我所做的更改是添加属性“name”,其值为“submit”。

其次,在您的第二段代码中,以下行可能是罪犯:

  

'payment_mode'=&gt; $ _POST [ 'payment_mode']

$ _POST中没有定义这样的键('payment_mode')(仅根据您提供的代码判断)。付款方式存储在密钥'delivery_options'中,稍后存储在变量$ payment_mode中。

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

  

'payment_mode'=&gt; $ _POST [ 'payment_mode']

  

'payment_mode'=&gt; $ _POST [ 'DELIVERY_OPTIONS']

  

'payment_mode'=&gt; $ payment_mode

答案 2 :(得分:1)

嗯,你没有发布完整的代码所以它会很难,但正如我所看到的那样,原因是没有保存,因为$_POST['payment_mode']没有在任何地方定义,而是将它存储在变量中。

所以改变这一行

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

到此

'payment_mode'    =>  $payment_mode 

答案 3 :(得分:0)

进行两项更改

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>
  2. 更改为

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