Re: One database, different forms

From: Date: Mon, 14 May 2001 16:13:08 +0000
Subject: Re: One database, different forms
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52698@lists.php.net to get a copy of this message
I use this code for dynamically creating queries almost every day. $column = mysql_list_fields("$db","$table"); for($i = 0; $i < mysql_num_fields($column); $i++) { $value = mysql_field_name($column,$i); $value = $$value; $values .= "'$value'"; if($i != mysql_num_fields($column)-1) $values .= ","; } $sql = "INSERT INTO $table VALUES ($values)"; mysql_query($sql); Ethan Schroeder ----- Original Message ----- From: "midget2000x" <midget@elaris.com> To: <php-general@lists.php.net> Sent: Sunday, May 13, 2001 1:31 PM Subject: [PHP] One database, different forms > I am writing a PHP application that will operate on a MySQL database. There > will be 4 types of forms (like catalog request, info request, etc.) calling > the code which writes the data to the database. > > Since the variable names on the forms will equal the MySQL column names (as they > should), I am wondering if there is a way for me to create my SQL statements on > the fly so that only data passed is written. Otherwise I'll have to create 8 > types of SQL statements...INSERT (if the record, keyed by e-mail address, > doesn't exist), and UPDATE (if the record does exist) for all 4 forms. > > For example, on my "add to mailing list" form, only the e-mail address is > collected. I'd like the PHP to recognize that only the 'email' field is passed > and create the SQL statement that only writes the e-mail to the database. > > Any ideas greatly appreciated! > > Thanks, > > Rory > > -- ----------- > providing the finest in midget technology > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#52698) next »