Escaping Multiple Post Values for MySQL with PHP


/ Published in: PHP
Save to your folder(s)

This is useful for escaping multiple values in a POST array.


Copy this code and paste it in your HTML
  1. foreach($_POST['your_array_here'] as &$val) {
  2. }
  3.  
  4. // FORM FIELDS EXAMPLE
  5. <input type="text" name="field[p_name]" id="field[p_name]" />
  6. <input type="text" name="field[p_email]" id="field[p_email]" />
  7.  
  8. // PHP PROCESSING EXAMPLE
  9. function process_form() {
  10. foreach($_POST['field'] as &$val) {
  11. }
  12.  
  13. extract($_POST['field']);
  14.  
  15. $sql = "INSERT INTO my_table (name, email) VALUES ('$p_name', '$p_email')";
  16.  
  17. mysql_query($sql) or die ('An error has occurred');
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.