我想要做的是从表单插入信用卡信息到我的MySQL数据库。 首先, 到期日期的输入格式将是MM/YY
(有或没有空格)的表格上,我试图连接"20"
字符串到年,但我总是得到"20 YY"
作为结果,它不能从mysql被认定为日期。从PHP字符串到MySQL日期
我想获得过期日期以适应格式,以便稍后可以将其更改为MySQL格式。有任何想法吗?
这是我到目前为止的代码:
<?php
$cc_number="";
$cc_expire="";
$cc_cvc="";
$cc_number=$_POST['number'];
$cc_expire=$_POST['expiry'];
$cc_cvc=$_POST['cvc'];
$cc_pid=$_SESSION['pid'];
/*edit the expire date*/
$pieces=explode("/", $cc_expire);
$expire_dd="01";
$expire_mm=$pieces[0];
$expire_yy="20".$pieces[1];
$expire_yy=trim($expire_yy, "\x00..\x1F");
//$cc_expire = $expire_yy.$expire_mm.$expire_dd;
//$cc_expire = date('Y-m-d', strtotime(str_replace('-', '/', $cc_expire)));
echo "expire_yy = ".$expire_yy;
//echo "cc_expire = ".$cc_expire;
if (isset($_POST["submit"])) {
if (empty($cc_number) || empty($cc_cvc) || empty($cc_expire)) {
echo "<p align='center'><font color='red'><br><br><br><br>All fields are mandatory.</font></p>";
}
else {
$cc_expire = date('Y-m-d', strtotime($cc_expire));
$sql = "INSERT INTO credit_card (credit_card_number, cvc, expiration_date, pid)
VALUES ('$cc_number', '$cc_cvc', '$cc_expire', $cc_pid)";
if ($dbconn->query($sql)) {
//echo "<script> window.location.assign('../card.php'); </script>";
}
else {
echo "<p align='center'><font color='red'><br><br><br><br>Something went wrong.</font></p>";
}
}
}
?>
我想对所有的牌来获得,这将是01-MM-YYYY MySQL的日期格式。
'print_r($ _ POST)的输出是什么;'? – AnkiiG
Mysql日期格式是yyyy-mm-dd,而不是'01-MM-YYYY'。什么是'expiration_date',varchar?示例代码中的$ cc_expire是什么?你也开放SQL注入这个.. – chris85