note 78161 deleted from control-structures.foreach by ezyang

From: Date: Wed, 03 Oct 2007 01:24:34 +0000
Subject: note 78161 deleted from control-structures.foreach by ezyang
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-131011@lists.php.net to get a copy of this message
Note Submitter: mike.mackintosh [AT] Angrystatic.com Reason: useless ---- 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 .'\''); } ?>

« previous php.notes (#131011) next »