yobo Posted March 20, 2010 Share Posted March 20, 2010 Hey all I have some old code that i did a while back but now that I am running php 6 it says the eregi function is depreciated I have tried replacing this old function with preg-match but I am unable to do so I was wondering if you all good take a look at my coding and see how i can remove the validation check altogether I have two pages the first page processes the orders <?php /* Program name: ProcessOrder.php * Description: Processes order when it's been submitted. */ session_start(); #5 include("functions_main.inc"); if(!isset($_SESSION['order_number'])) #7 { echo "No order number found<br>\n"; header("Location: ShopCatalog.php"); exit(); } if(@$_GET['from'] == "cart") #13 { include("fields_ship_info.inc"); include("single_form.inc"); exit(); } elseif(isset($_POST['Summary'])) #19 { foreach($_POST as $field => $value) #21 { if ($value == "") { $blanks[] = $field; } } if(isset($blanks)) { $message = "The following fields are blank. Please enter the required information: "; foreach($blanks as $value) { $message .="$value, "; } extract($_POST); include("fields_ship_info.inc"); include("single_form.inc"); exit(); } foreach($_POST as $field => $value) #41 { if($field != "Summary") { if(eregi("name",$field)) { if (!ereg("^[A-Za-z' -]{1,50}$",$value)) { $errors[] = "$value is not a valid name."; } } if(eregi("street",$field)or eregi("addr",$field) or eregi("city",$field)) { if(!ereg("^[A-Za-z0-9.,' -]{1,50}$",$value)) { $errors[] = "$value is not a valid address or city."; } } if(eregi("county",$field)) { if(!ereg("[A-Za-z]",$value)) { $errors[] = "$value is not a valid state."; } } if(eregi("email",$field)) { if(!ereg("^.+@.+\\..+$",$value)) { $errors[]="$value is not a valid email address."; } } if(eregi("postcode",$field)) { if(!ereg("^[0-9]{5,5}(\-[0-9]{4,4})?$",$value)) { $errors[] = "$value is not a valid zipcode."; } } if(eregi("phone",$field)) { if(!ereg("^[0-9)(xX -]{7,20}$",$value)) { $errors[]="$value is not a valid phone number. "; } } if(eregi("cc_number",$field)) { $value = trim($value); $value = ereg_replace(' ','',$value); $value = ereg_replace('-','',$value); $_POST['cc_number'] = $value; if($_POST['cc_type'] == "visa") { if(!ereg("^[4]{1,1}[0-9]{12,15}$",$value)) { $errors[]="$value is not a valid Visa number. "; } } elseif($_POST['cc_type'] == "mc") { if(!ereg("^[5]{1,1}[0-9]{15,15}$",$value)) { $errors[] = "$value is not a valid Mastercard number. "; } } else { if(!ereg("^[3]{1,1}[0-9]{14,14}$",$value)) { $errors[] = "$value is not a valid American Express number. "; } } } $$field = strip_tags(trim($value)); } } if(@is_array($errors)) { $message = ""; foreach($errors as $value) { $message .= $value." Please try again<br />"; } include("fields_ship_info.inc"); include("single_form.inc"); exit(); } #132 /* Process data when all fields are correct */ foreach($_POST as $field => $value) #134 { if(!eregi("cc_",$field) && $field != "Summary" ) #136 { $value = addslashes($value); $updates[] = "$field = '$value'"; } } $update_string = implode($updates,","); #142 $sql_ship = "UPDATE Customer_Order SET $update_string WHERE order_number='{$_SESSION['order_number']}'"; $cxn = connect_to_db("Vars.inc"); $result = mysqli_query($cxn,$sql_ship) or die(mysqli_error($cxn)); extract($_POST); #148 include("fields_summary.inc"); include("summary_page.inc"); } elseif(isset($_POST['Ship'])) #152 { include("fields_ship_info.inc"); include("single_form.inc"); } elseif(isset($_POST['Final'])) #157 { switch ($_POST['Final']) #159 { case "Continue Shopping": #161 header("Location: ShopCatalog.php"); break; case "Cancel Order": #164 #include("fields_cancel.inc"); #include("cancel_message.inc"); unset($_SESSION['order_number']); session_destroy(); exit(); break; case "Submit Order": #171 $cxn = connect_to_db("Vars.inc"); $sql = "UPDATE Customer_Order SET submitted='yes' WHERE order_number='{$_SESSION['order_number']}'"; $result = mysqli_query($cxn,$sql) or die("Error: ".mysqli_error($cxn)); #processCCInfo(); #177 #sendOrder(); #include("fields_accept.inc"); #179 #include("accept_message.inc"); #email(); #181 session_destroy(); #182 break; } } ?> this pages contains the fileds <?php /* File: fields_ship_info.inc * Desc: Contains arrays with the field names and form * elements for the login Web page. */ $page = array( "title" => "Food Shop Order: Shipping Information", "top" => "Food Shop Order: Shipping Information", "top2" => "Please fill in the information below", "bottom" => "Joe Moore", ); $ship_info = array("email" => "Email Address", "ship_name" => "Name", "ship_street" => "Street", "ship_city" => "City", "ship_county" => "County", "ship_postcode" => "Postcode", "phone" => "Phone", "cc_type" => "Credit Card Type", "cc_number" => "Credit Card Number", "cc_exp" => "Expiration Date" ); $cc_types = array("visa" => "Visa", "mc" => "Master Card", "amex" => "American Express" ); $length = array("email" => "55", "ship_name" => "40", "ship_street" => "55", "ship_city" => "40", "ship_postcode" => "8", "phone" => "15", "cc_number" => "20" ); $elements = array( "submit" => "Continue"); $months = array (1=> "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ); $today = time("Y-m-d"); if(!isset($_POST['state'])) { $connect = connect_to_db("Vars.inc"); #47 $sql = "SELECT ship_name,ship_street,ship_city,ship_county,ship_postcode, phone,email FROM Customer_Order WHERE order_number = '{$_SESSION['order_number']}'"; $result = mysqli_query($connect,$sql) or die("Error: ".mysqli_error($connect)); $n = mysqli_num_rows($result); #54 if($n > 0) #55 { $row = mysqli_fetch_assoc($result); extract($row); } } ?> Link to comment https://forums.phpfreaks.com/topic/195913-eregi-problems-moving-to-preg-match/ Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 have a look at this <?php if(ereg('[^0-9A-Za-z]',$test_string)) // will be true if characters arnt 0-9, A-Z or a-z. if(preg_match('/[^0-9A-Za-z]/',$test_string)) // this is the preg_match version. the /'s are now required. ?> Link to comment https://forums.phpfreaks.com/topic/195913-eregi-problems-moving-to-preg-match/#findComment-1029089 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 Sorry ignore that post above, I used ereg which has been removed... <?php // The "i" after the pattern delimiter indicates a case-insensitive search if (preg_match("/php/i", "PHP is the web scripting language of choice.")) { echo "A match was found."; } else { echo "A match was not found."; } ?> Have a look at that. Link to comment https://forums.phpfreaks.com/topic/195913-eregi-problems-moving-to-preg-match/#findComment-1029097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.