Re: php and sql problem with mysql_query and insert

From: Date: Wed, 29 Jan 2003 08:09:08 +0000
Subject: Re: php and sql problem with mysql_query and insert
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-133465@lists.php.net to get a copy of this message
At 05:17 29.01.2003, Sunfire said: --------------------[snip]-------------------- >hi ... > >im having a little problem with mysql_query("insert into members >('$company', '$name1', '$name2', '$address1', >'$address2', ''$ac1', '$ext2', >'$num1', '$ac2', '$ext2', '$num2', '$city', >'$state', '$zip', '$desc', >'$flags')"); > >for some reason those variables are empty by the time they get into the >table... Are these variables received by handling a form submit? You should use the $_REQUEST array if you have register_globals off: mysql_query("insert into members ('{$_REQUEST['company']}', '{$_REQUEST['name1']}', '{$_REQUEST['name2']}', '{$_REQUEST['address1']}', '{$_REQUEST['address2']}', '{$_REQUEST['ac1']}', '{$_REQUEST['ext2']}', '{$_REQUEST['num1']}', '{$_REQUEST['ac2']}', '{$_REQUEST['ext2']}', '{$_REQUEST['num2']}', '{$_REQUEST['city']}', '{$_REQUEST['state']}', '{$_REQUEST['zip']}', '{$_REQUEST['desc']}', '{$_REQUEST['flags']}')"); Two other 'littles' I see: - your original statement comes with two single quotes before "$ac1", this will break the query if it's not a message typo here. - the "ext2" value is inserted twice - I personally prefer to explicitly name the columns on any insert, even if I populate all columns. If by chance your table structure will change (using ALTER TABLE) your insert statement will break. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#133465) next »