Posted By

bradless on 02/08/10


Tagged

mysql php security


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tapdrup


Escaping Multiple Post Values for MySQL with PHP


 / Published in: PHP
 

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

  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  

You need to login to post a comment.