Inserting string - need to trim comma

From: Date: Thu, 01 Apr 2004 18:56:52 +0000
Subject: Inserting string - need to trim comma
Groups: php.general 
Request: Send a blank email to php-general+get-182058@lists.php.net to get a copy of this message
Hi - I'm trying to create a very basic function that add the results of a form to my database. I have this code so far, with $table being the table name and the $data is an exact copy of the $_POST array. function insert($table, $data) { $sql = "INSERT INTO ".$table." SET "; foreach ($data as $k=>$v) { $sql.= $k." = '".$v."', "; } $sql.=";"; $result = mysql_query($sql); } The only problem with the statement is the appended comma to each iteration - the statement generates a mysql error with the extra comma at the end of the statement. This seems like an easy fix -any ideas? Any help would be greatly appreciated... ------------------------------------------------------------ http://www.phreshdesign.com

« previous php.general (#182058) next »