note 39102 deleted from function.mysql-query by cece

From: Date: Sun, 14 Nov 2004 13:19:50 +0000
Subject: note 39102 deleted from function.mysql-query by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80499@lists.php.net to get a copy of this message
Note Submitter: scott at millerco dot net ---- Here is a handy little function to upload the information from a html form to a MySQL database. Keep in mind that it does not do any data validation. You will have to add your own security features. $form_data is an associative array containing $_POST or $_GET data. $table is the name of the table that you would like the data inserted into. Be aware that the names of the fields in your form will have to match the names in you database or it will not work. You can unset any extra fields that you wish to omit. function form_data_query ($form_data, $table) { unset ($form_data["Submit"]); $query = "INSERT INTO "; $column = "inventory ("; $data = "VALUES ("; foreach ( $form_data as $key => $value ) { $column .= "$key, "; $data .= "'$value', "; } $column = rtrim($column, ", "); $data = rtrim($data, ", "); $query = $query . $column . ") " . $data . ") "; return $query; }

« previous php.notes (#80499) next »