gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 18:59:10 24 4
gpt4 key购买 nike

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

当我点击完成订单时,我的数据库在数据库中记录amazon_code,但我试图记录gift_pingift_card_name > 这两个数据也是如此。当按完成订单时,我需要将这两个数据直接添加到数据库中。请帮忙

<?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>

最佳答案

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 (:
}

此外,您的标题拼写错误,给人一种错觉,以为这是您想要添加到数据库的日期。对于任何想添加日期的人,请在您的 PHP 脚本中通过 microseconds(true); 方法将 BIGINT 添加到数据库。

关于javascript - 表单提交后将日期存储到 MySQL 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43990720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com