JREAM Posted October 14, 2008 Share Posted October 14, 2008 Hey can anyone help me make this $required array check the values in the for loop? You can see what im trying to do pretty basic Just scroll to the bottom where // Validate is! Please! <?php // Top Two $package = $_POST['package']; $time_frame = $_POST['time_frame']; // Details $company = $_POST['company']; $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $address = $_POST['address']; $city_state_zip = $_POST['city_state_zip']; $purchase_order = $_POST['purchase_order']; // Site Details $site_details = $_POST['site_details']; $i_have = $_POST['i_have']; $sites_you_like = $_POST['sites_you_like']; // If Submitted if (isset($_POST['submit'])) { // Required $required = array ($package, $time_frame, $name, $email, $phone, $address, $city_state_zip); // Validate for ($i = 0; $i < count($required); $i++) { if ($required[$i] = '') { echo 'error' . $required ; } } } else {echo 'good';} ?> Link to comment https://forums.phpfreaks.com/topic/128303-my-array-wont-check-the-values/ Share on other sites More sharing options...
R0bb0b Posted October 14, 2008 Share Posted October 14, 2008 You need a double = <?php // Top Two $package = $_POST['package']; $time_frame = $_POST['time_frame']; // Details $company = $_POST['company']; $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $address = $_POST['address']; $city_state_zip = $_POST['city_state_zip']; $purchase_order = $_POST['purchase_order']; // Site Details $site_details = $_POST['site_details']; $i_have = $_POST['i_have']; $sites_you_like = $_POST['sites_you_like']; // If Submitted if (isset($_POST['submit'])) { // Required $required = array ($package, $time_frame, $name, $email, $phone, $address, $city_state_zip); // Validate for ($i = 0; $i < count($required); $i++) { if ($required[$i] == '') { echo 'error' . $required ; } } } else {echo 'good';} ?>/code] Link to comment https://forums.phpfreaks.com/topic/128303-my-array-wont-check-the-values/#findComment-664623 Share on other sites More sharing options...
kenrbnsn Posted October 14, 2008 Share Posted October 14, 2008 A better way of doing this would be to put the names of the fields in the required array and check the actual posted values: <?php $required = array('package','time_frame','name','email','phone','address','city_state_zip'); if (isset($_POST['submit'])) { foreach ($required as $fld) if (strlen(trim(stripslashes($_POST[$fld]))) == 0) echo 'Field ' . $fld . ' required'; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/128303-my-array-wont-check-the-values/#findComment-664626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.