2690

How to put a lot of form values into an associative array in PHP

When creating a form with many input items, it would be cumbersome if we had to put them into variables one by one, so we used foreach as a to put them in the array at once.

The value is put in the associative array, which makes the subsequent process easier.

If you want to put the value of $_POST in a session variable in a similar way, you can do the following

foreach($_POST as $key => $val){
    $_SESSION[$key] = $val;
}

Since it’s only an input value, you can use htmlspecialchars to display it in html using When adding to MySQL, use mysql_real_escape_string I hope you can do this.

Exit mobile version