Posted By

psradich111 on 12/27/11


Tagged

mysql post to


Versions (?)

PHP All POST Vars to MySql


 / Published in: PHP
 

requires Ultimate MySQL Class http://www.phpclasses.org/package/3698-PHP-MySQL-database-access-wrapper.html

  1. // PHP All POST Vars to MySql
  2. // Paul Radich [email protected]
  3.  
  4. // Dependencies : mysql.class.php http://www.phpclasses.org/package/3698-PHP-MySQL-database-access-wrapper.html
  5.  
  6. //Include DB Class
  7. include("mysql.class.php");
  8.  
  9.  
  10. //Global Vars
  11. $db = new MySQL();
  12. $vars = array();
  13. $tableName = "";
  14. $keys = "";
  15. $vals = "";
  16.  
  17.  
  18. //Build Query Vals from Post Vals
  19. foreach ($_POST as $key => $value) {
  20. if($key != "submit"){
  21. if (strlen($keys) == 0) {$keys = $key;} else { $keys .= ", " . $key ;}
  22. if (strlen($vals) == 0) {$vals = "'" . mysql_real_escape_string($value) . "'"; } else {$vals .= ", '" . mysql_real_escape_string($value) . "'";}
  23. }
  24. }
  25.  
  26.  
  27. //Exacute Query
  28. $db->Query("INSERT INTO " . $tableName . " (".$keys.") Values (" . $vals.")");

Report this snippet  

You need to login to post a comment.