Re[2]: [PHP] Inserting string - need to trim comma

2004-04-01 Thread Tom Rogers
Hi, Friday, April 2, 2004, 5:10:29 AM, you wrote: MM> 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 st

Re: [PHP] Inserting string - need to trim comma

2004-04-01 Thread Chris Shiflett
--- "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 incl

Re: [PHP] Inserting string - need to trim comma

2004-04-01 Thread John W. Holmes
From: "Matt Matijevich" <[EMAIL PROTECTED]> > > 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)

Re: [PHP] Inserting string - need to trim comma

2004-04-01 Thread Doug Parker
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 -

Re: [PHP] Inserting string - need to trim comma

2004-04-01 Thread Matt Matijevich
--- Matt Matijevich <[EMAIL PROTECTED]> wrote: > http://www.php.net/rtrim rtrim() trims whitespace, not commas. Hope that helps. Chris string rtrim ( string str [, string charlist]) there is a second optional paremeter you can add to rtrim rtrim($var,','); will take any trailing commas o

Re: [PHP] Inserting string - need to trim comma

2004-04-01 Thread Chris Shiflett
--- 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 sta

Re: [PHP] Inserting string - need to trim comma

2004-04-01 Thread Matt Matijevich
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 wit

[PHP] Inserting string - need to trim comma

2004-04-01 Thread Doug Parker
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