note 39102 added to function.mysql-query

From: Date: Fri, 16 Jan 2004 23:17:10 +0000
Subject: note 39102 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-63715@lists.php.net to get a copy of this message
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; } ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39102 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39102&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39102&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63715) next »