Kenny Pollock Posted March 20, 2008 Share Posted March 20, 2008 I submit four form input fields. I leave one blank, and submit. All four are added to the database via the INSERT query below. Even though vin, make, model, color and amount are left blank, the empty row still makes it to the database. Only the three that had data should've made it in. I did a print_r($_POST) and it confirms... the row I submitted has all empty values. WHY IS IT GETTING INTO THE DATABASE THEN? // UPDATE ORDER if ( $_POST['update_order'] ) { foreach ($_POST['veh_id'] as $x=>$value) { if ( $value > 0 ) { mysql_query( "UPDATE order_vehicles SET vin='" . $_POST['vin'][$x] . "', make='" . addslashes( $_POST['make'][$x] ) . "', model='" . addslashes( $_POST['model'][$x] ) . "', color='" . addslashes( $_POST['color'][$x] ) . "', yr='" . $_POST['yr'][$x] . "', amt='" . $_POST['amt'][$x] . "', op='" . $_POST['op'][$x] . "', uid='" . $user . "' WHERE id = '" . $value . "'" ); } else { if ( empty( $_POST['vin'][$x] ) && empty( $_POST['make'][$x] ) && empty( $_POST['model'][$x] ) && empty( $_POST['color'][$x] ) && empty( $_POST['amt'] ) ) { } else { mysql_query( "INSERT INTO order_vehicles(id, cc_id, order_id, num, vin, make, model, color, yr, mileage, amt, op, ccarrier, notes, uid, dtime) VALUES ('', 1, " . $_POST['order_id'] . ", 1, '" . $_POST['vin'][$x] . "', '" . addslashes( $_POST['make'][$x] ) . "', '" . addslashes( $_POST['model'][$x] ) . "', '" . addslashes( $_POST['color'][$x] ) . "', '" . $_POST['year'][$x] . "', '', '" . $_POST['amt'][$x] . "', '" . $_POST['op'][$x] . "', '', '', '" . $user . "', CURDATE() )" ); } } } //redirect( 'Updating order', 'order' ); print_r($_POST); } Link to comment https://forums.phpfreaks.com/topic/97137-empty-array/ Share on other sites More sharing options...
rhodesa Posted March 20, 2008 Share Posted March 20, 2008 The 'amt' in your IF is missing [$x] change if ( empty( $_POST['vin'][$x] ) && empty( $_POST['make'][$x] ) && empty( $_POST['model'][$x] ) && empty( $_POST['color'][$x] ) && empty( $_POST['amt'] ) ) to if ( empty( $_POST['vin'][$x] ) && empty( $_POST['make'][$x] ) && empty( $_POST['model'][$x] ) && empty( $_POST['color'][$x] ) && empty( $_POST['amt'][$x] ) ) Link to comment https://forums.phpfreaks.com/topic/97137-empty-array/#findComment-497026 Share on other sites More sharing options...
Kenny Pollock Posted March 20, 2008 Author Share Posted March 20, 2008 Thank you so much!! Link to comment https://forums.phpfreaks.com/topic/97137-empty-array/#findComment-497051 Share on other sites More sharing options...
Kenny Pollock Posted March 20, 2008 Author Share Posted March 20, 2008 Question... instead of if(empty(this) and empty(that)) { } else { action } How would I go about getting rid of the if and going straight to the else? I only need action if they're all empty. I would do if(!empty(this) and !empty(that) but then it would only work if they were all filled out. Link to comment https://forums.phpfreaks.com/topic/97137-empty-array/#findComment-497057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.