Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/09/2022 in all areas

  1. @gizmola - Got everything fixed - had to better define DocumentRoot path for both. I appreciate your continued support.
    1 point
  2. what you are missing, relevant to both my reply above and the reply by @Barand, is a table where the (currently 3) vehicle choices are DEFINED. it is this definition that will allow you to produce the checkbox markup without writing out code for every possible value. see the following example form processing/form code, related to the method stated in my reply above (there are comments in the code at the point where you would query for and retrieve the existing data to be edited) - <?php // you would query to get the following data from whereever it is stored // assuming that $table in the OP's code is an array of fetched data defining the checkbox choices $table = []; // the index is the id // do you really want the 'I have a' text with every entry? how about just a heading to select the vehicles the user has? $table[1] = ['name'=>'I have a yacht']; $table[2] = ['name'=>'I have a super car']; $table[3] = ['name'=>'I have a plane']; $post = []; // array to hold a trimmed working copy of the form data $errors = []; // array to hold user/validation errors // recursive function to trim data function _trim($val){ if(is_array($val)){ return array_map('_trim',$val); } else { return trim($val); } } // post method form processing code if($_SERVER['REQUEST_METHOD'] == 'POST') { // trim all the data at once $post = array_map('_trim',$_POST); // validate the data here, storing validation errors in $errors, using the field name as the array index // if no errors, use the submitted data if(empty($errors)) { // insert new data or update existing data here... } } // get method business logic - get/produce data need to display the dynamic content on the page // if editing existing saved choices, there would be a get input to validate, then used to query // for and retrieve the existing choice data, but only if the form has never been submitted ($post // is empty), storing the fetched data in $post, in a sub-array named 'vehicle', in the same format // as the form will submit it as. // html document starts here... ?> <form method='post'> <?php // display the checkboxes, with any existing choices pre-checked foreach($table as $id=>$arr) { $chk = in_array($id,$post['vehicle'] ?? []) ? ' checked' : ''; // note: if you put the <label></label> around the form field, you don't need to generate unique ids to make it work echo "<label class='boxstyle'><input type='checkbox' name='vehicle[]' value='$id'$chk> {$arr['name']}</label><br>\n"; } ?> <input type='submit'> </form>
    1 point
  3. all that did was hide the actual problem. if your code is expecting an array of data as its input, it's an application error if it isn't. either a programming mistake or an incorrect user action (directly requesting a delete action page without first visiting the page selecting what to delete) caused the expected input to not be the expected data type. for programming mistakes, you need to find an fix the root cause of the problem. for an incorrect user action, you need to setup and display a message telling the user either what they did wrong, i.e. you cannot directly request this page, or what they need to do to correct the problem, i.e. you must select at least one notification to delete.
    1 point
  4. wherever you found this, forget you saw it. here's everything that's bad about this - don't use output buffing unless you WANT to buffer output. by using it to make bad code work, you are hiding mistakes in the code and it will make finding and fixing problems harder. don't conditionally start a session. if you want to use sessions, simply, unconditionally start them once, in an initialization/configuration file. as already stated about the error, and stated in the documentation for session_set_cookie_params(), you must call this before the session_start. session_set_cookie_params(0) is only valid in php8, where that usage would set the session.cookie_lifetime to zero, but the default is already zero. set_time_limit(0) and ini_set('max_execution_time','3600') set the same thing, so these are first setting the max_execution_time to zero (which you should never do since a programming mistake that causes a script to never end will require that you restart the web server to regain control), then sets it to 3600. you cannot set post_max_size in a php script, because the value is used by the server before a php script is ever invoked.
    1 point
  5. 1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.