[thelist] PHP tip

Rob Whitener rwhitener at DesignOptions.com
Tue Feb 4 08:36:01 CST 2003


I wanted to post a tip, something I use for iserting records into a database
with PHP.  Pretty basic stuff, but it may help the beginners.

<tip type="PHP insert with MySQL" author = "Rob">
When inserting records into a database from PHP and an HTML form, ensure the
names of the form fields correspond to the names of columns in your table,
then you can use this code to quicly build an INSERT string:

	$insert = "INSERT INTO ".$tablename."(";
	$insert .= implode(",",$columns).") VALUES
(\"".implode("\",\"",$values)."\")";
where $tablename is the name of your table, $columns is an array of column
names retrieved from either $_POST or $_GET as keys and $values is another
array which contain the values from $_POST or $_GET.  lookup foreach for an
easy way to get keys and values from an array.

Enjoy

</tip>



More information about the thelist mailing list