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
snip
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
--- Doug Parker [EMAIL PROTECTED] wrote:
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
snip
--- Matt Matijevich [EMAIL PROTECTED] wrote:
http://www.php.net/rtrim
rtrim() trims whitespace, not commas.
Hope that helps.
Chris
/snip
string rtrim ( string str [, string charlist])
there is a second optional paremeter you can add to rtrim
rtrim($var,',');
will take any trailing
implode() worked perfectly.
thanks -
doug
- Original Message -
From: Chris Shiflett [EMAIL PROTECTED]
To: Doug Parker [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 2:19 PM
Subject: Re: [PHP] Inserting string - need to trim comma
--- Doug Parker [EMAIL PROTECTED
From: Matt Matijevich [EMAIL PROTECTED]
snip
function insert($table, $data) {
$sql = INSERT INTO .$table. SET ;
foreach ($data as $k=$v) {
$sql.= $k. = '.$v.', ;
}
$sql.=;;
Take out the above line; you don't need to add the semi-colon
$result = mysql_query($sql);
}
The only
--- John W. Holmes [EMAIL PROTECTED] wrote:
http://www.php.net/rtrim
rtrim() removes whitespace, not commas.
That's exactly what I thought (and said). :-)
Matt corrected me by pointing out a second, optional argument added in
4.1.0 where you can specify one or more characters to include in
Hi,
Friday, April 2, 2004, 5:10:29 AM, you wrote:
MM snip
MM function insert($table, $data) {
MM $sql = INSERT INTO .$table. SET ;
MM foreach ($data as $k=$v) {
MM $sql.= $k. = '.$v.', ;
MM }
MM $sql.=;;
MM $result = mysql_query($sql);
MM }
MM The only problem with the statement is the
8 matches
Mail list logo