表单提交后将日期存储到MySQL数据库中

时间:2017-05-16 00:30:14

标签: javascript php mysql

这是我的代码,之前很少,但这里是主要代码。

当我点击完成订单时,我的数据库在数据库中记录amazon_code,但我正在尝试记录gift_pin& gift_card_name这两个数据也是如此。按完成订单时,我需要直接在db中添加这两个数据。请帮忙



<?php if (isset($this->data['amazon'])) { ?>
                            	<input type="hidden" id="payment_method" value="amazon" />
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group" id="group-amazon_code">
                                            <label class="col-xs-12  form-control-label">Gift Card Number:
                                                <span class="muted small">(this is the code under the scratch off area)</span>
                                            </label>
                                            <div class="col-md-12">
                                                <input type="text" autocomplete="yes" value="" class="form-control" name="amazon_code" id="amazon_code" placeholder="Amazon Gift card # (under scratch off)" />
                                                <label for="amazon_code" class="error">Error Text</label>
                                            </div>
                                        </div>
                                        
                                        
                                        
                                         <div class="form-group" id="group-amazon_code">
                                            <label class="col-xs-12  form-control-label">PIN</label>
                                            <div class="col-md-12">
                                                <input type="text" autocomplete="yes" value="" class="form-control" name="gift_pin" id="gift_pin" placeholder="Enter PIN #" />
                                                <label for="gift_pin" class="error">Error Text</label>
                                            </div>
                                        </div>
                                        
                                        
                                        
                                        <div class="form-group">
						<label for="human" class="col-sm-4 control-label">Gift Card Name:</label>
						<div class="col-sm-8">
                        	<select class="form-control" name="gift_card_name">
                            	<option <?php if($this->data['gift_card_name'] == 'PayPal') echo 'selected="selected"'; ?> value="PayPal">PayPal</option>
                                <option <?php if($this->data['gift_card_name'] == 'eBay') echo 'selected="selected"'; ?> value="eBay">eBay</option>
                                <option <?php if($this->data['gift_card_name'] == 'Google') echo 'selected="selected"'; ?> value="Google">Google</option>
                                <option <?php if($this->data['gift_card_name'] == 'iTunes') echo 'selected="selected"'; ?> value="iTunes">iTunes</option>
                                <option <?php if($this->data['gift_card_name'] == 'BestBuy') echo 'selected="selected"'; ?> value="BestBuy">BestBuy</option>
                            <option <?php if($this->data['gift_card_name'] == 'Hotels.com') echo 'selected="selected"'; ?> value="Hotels.com">Hotels.com</option>
                            <option <?php if($this->data['gift_card_name'] == 'Bass Pro') echo 'selected="selected"'; ?> value="Bass Pro">Bass Pro</option>
                            </select>
						</div>
					</div>
					
					
                                        
                                    </div>
                                </div>

                            <?php } // End of Amazon?>


                            <div class="row">
                                <div class="col-xs-12">
                                    <div class="alert alert-info">
                                        <div class="row">
                                            <div class="col-xs-6">
                                                <div class="panel">
                                                    <div class="panel-body">
                                                        <h4 class="text-center">Credits</h4>
                                                        <h2 class="credits_text credits text-center"></h2>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-xs-6">
                                                <div class="panel">
                                                    <div class="panel-body">
                                                        <h4 class="text-center">Order Total</h4>
                                                        <h2 class="price_text text-success text-center"></h2>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                        </div>
                        <!-- STEP 3 -->


                    </div>
                    <div class="clearfix"></div>

                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        <div class="clearfix block"></div>
        <div class="row">
            <div class="col-sm-4 col-xs-6">
                <a href="#" class="btn btn-block btn-default btn-lg prev-btn">Previous Step</a>
            </div>
            <div class="col-sm-8 col-xs-6">
                <a href="#" class=" btn btn-block btn-lg btn-success next-btn">Next Step</a>
                <a href="#hasErrors" class=" btn btn-block btn-lg btn-primary finish-btn" data-submit="<?php echo (isset($this->data['amazon'])) ? 'amazonprocess' : 'process'; ?>">
                    <span class="fa fa-shopping-cart" aria-hidden="true"></span>
                    Complete Order
                </a>
            </div>
        </div>
    </form>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

      var byteStr = event.target.response;
      var byteArray = byteStr.replace('[', '').replace(']', '').split(','); //error occurs at this line
      var fileName = event.target.getResponseHeader('filename');
      var uint8_array = new Uint8Array(byteArray);
      var bb = new Blob([uint8_array], {
        type: 'application/octet-stream'
      });
      if (window.navigator['msSaveBlob']) {
        window.navigator['msSaveBlob'](bb, fileName);
      } else {
        this.download(window.URL.createObjectURL(bb), fileName);
      }

此外,您的标题拼写错误,并表示您希望将其添加到数据库中。对于想知道添加日期的人,在php脚本中从if(isset($_POST['gift_pin']) && isset($_POST['gift_card_name'])){ $giftPin = $_POST['gift_pin']; //Sanitize it too. $giftCardName = $_POST['gift_card_name']; //Sanitize it too. /* * INCASE YOU MISSED IT: SANITIZE YOUR INPUTS. OR ELSE PEOPLE CAN USE * SQL INJECTION TO STEAL ALL OF YOUR DATA, AND MAKE YOU LOOK LIKE A * FOOL. PREPARED STATEMENTS SHOULD BE USED WHEREVER POSSIBLE, Thanks */ //Add in all your other stuff you want in the database too. $query = "INSERT INTO ultraCoolTable (gift_pin, gift_card_name) VALUES (" . $giftPin . ", '" . $giftCardName . "');"; $result = mysqli_query($connection, $query); //Normal Stuff you'd do here, redirect maybe, check if it was added maybe. Whatever you want. }else{ //Something wasn't filled in, you should ideally not allow them to click the button by adding the required attribute to all the fields necessary but hey-ho... better redirect them or something (: } 方法向数据库添加BIGINT