我得到它的工作,对不起,伙计们......我不应该把 $_POST 再次放入 $stm
下面的代码是我出于安全目的收到发布值的地方,我打算放 preg_replace 函数..但它不起作用?
<?php
if (isset($_POST['cartOutput'])) {
$customer_name = preg_replace("/[^A-Za-z0-9 ]/", '', $_POST['customer_name']);
更多代码...这可能会导致问题?我检查了我的 php 它没有过滤
<?php
if (isset($_POST['cartOutput'])) {
$customer_name = preg_replace('/[^A-Za-z0-9 ]/', '', $_POST['customer_name']);
$tel_num = $_POST['tel_num'];
$customer_address = $_POST['customer_address'];
$error_status = false;
if (empty($_POST['customer_name'])){
echo '<a href="cart.php">Please Fill Your Name</a>';
$error_status = true;
}
if (empty($_POST['tel_num'])){
echo '</br><a href="cart.php">Please Fill Your Contact Number</a></br>';
$error_status = true;
}
if (empty($_POST['customer_address'])){
echo'<a href="cart.php">Please Fill Your Address</a></br>';
$error_status = true;
}
if(!$error_status) {
$sql= 'INSERT INTO orders (customer_name,tel_num,customer_address,product_name, price, quantity, date_added,customer_messages) VALUES(?,?,?,?,?,?,NOW(),?)';
$stmt = $myConnection->prepare($sql);
$countArray = count($_POST["item_name"]);
for ($i = 0; $i < $countArray; $i++) {
$stmt->bind_param('sssssss', $_POST['customer_name'],$_POST['tel_num'],$_POST['customer_address'], $_POST['item_name'][$i], $_POST['amount'][$i], $_POST['quantity'][$i],$_POST['customer_messages']);
$stmt->execute();
}
;