php - preg_replace function set but not working -
i working, sorry guys...i should not put $_post again inside $stm
the below code received posted value security purpose, plan put preg_replace function..but not working?
<?php if (isset($_post['cartoutput'])) { $customer_name = preg_replace("/[^a-za-z0-9 ]/", '', $_post['customer_name']);
more code ...which might cause problem? checked php didn't filter
<?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 name</a>'; $error_status = true; } if (empty($_post['tel_num'])){ echo '</br><a href="cart.php">please fill contact number</a></br>'; $error_status = true; } if (empty($_post['customer_address'])){ echo'<a href="cart.php">please fill address</a></br>'; $error_status = true; } if(!$error_status) { $sql= 'insert 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"]); ($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(); } ;
that looks fine me! maybe check customer_name has value first?
$text = "h^&%*ello"; $new = preg_replace("/[^a-za-z0-9 ]/", '', $text); echo $new; output: hello
when testing here http://writecodeonline.com/php/ correct result syntax looks fine! try ensuring there value!
Comments
Post a Comment