note 78161 added to control-structures.foreach

From: Date: Mon, 01 Oct 2007 15:15:36 +0000
Subject: note 78161 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-130959@lists.php.net to get a copy of this message
I like to make things as dynamic and modular as i can. If i have a table with the fields named the same as the text fields in a form, there is an easy way to insert them into the MySQL database. Ex: <form action="whatever.php" method="post"> <input name="FirstName"> <input name="LastName"> <input name="Address"> </form> You can use: <?php // Lets get the next available ID $NumRows = SQL::getSingleton()->sqlFetchrow(SQL::getSingleton()->sqlQuery('SELECT ID FROM field ORDER BY ID DESC')); $ID = $NumRows['ID'] + 1; // Make a parent record SQL::getSingleton()->sqlQuery('INSERT INTO field (ID) VALUES (\''. $ID .'\')'); // Add Each Field while(list($Field, $Value) = each($_POST)) { SQL::getSingleton()->sqlQuery('UPDATE field SET '.$Field.' = \''. $Value .'\' WHERE ID = \''. $ID .'\''); } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 67.80.110.114 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/78161 Del: integrated -- https://master.php.net/note/delete/78161/integrated Del: useless -- https://master.php.net/note/delete/78161/useless Del: bad code -- https://master.php.net/note/delete/78161/bad+code Del: spam -- https://master.php.net/note/delete/78161/spam Del: non-english -- https://master.php.net/note/delete/78161/non-english Del: in docs -- https://master.php.net/note/delete/78161/in+docs Del: other reasons-- https://master.php.net/note/delete/78161 Reject -- https://master.php.net/note/reject/78161 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130959) next »