1

私はそれを機能させます、ごめんなさい... $_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();
}
 ; 
4

2 に答える 2