[PHP-DB] Problem w/query - again
Dear list - This did not seem to post, so I am sending it again. If it did post, and I missed it, my apologies. Ethan Dear list - I have the following code: $query = select * from Intake3 where 1; $allowed_fields = array('Site', 'MedRec', 'Fname', 'Lname', 'Phone', 'Sex', 'Height'); foreach ( $allowed_fields AS $field = $_POST['field']) { if ( ! empty( $_POST['field'] ) ) { $query .= AND '$field' = '$_POST[$field]' ; echo $query; } } This is the value of $_POST: Array ( [Site] = AA [MedRec] = 1 [Fname] = [Lname] = [Phone] = [Height] = [welcome_already_seen] = already_seen ) I receive the following errors on run: Notice: Undefined offset: 0 in /var/www/srchrhsptl4.php on line 135 select * from Intake3 where 1 AND '0' = '' Notice: Undefined offset: 1 in /var/www/srchrhsptl4.php on line 135 select * from Intake3 where 1 AND '0' = '' AND '1' = '' Notice: Undefined offset: 2 in /var/www/srchrhsptl4.php on line 135 select * from Intake3 where 1 AND '0' = '' AND '1' = '' AND '2' = '' Advice and help please. Thanks. Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problem w/query - again
Dear Ethan It seems you are trying to build a query.But you are not getting field names. If you required field names then change the following line to foreach ( $allowed_fields AS $field = $_POST['field']) to foreach ( $allowed_fields AS $field) This would convert the variable field to value. In yoyr line the variable field is treated as array index regds amit The difference between fiction and reality? Fiction has to make sense. On Fri, Feb 10, 2012 at 9:40 AM, Ethan Rosenberg eth...@earthlink.netwrote: Dear list - This did not seem to post, so I am sending it again. If it did post, and I missed it, my apologies. Ethan Dear list - I have the following code: $query = select * from Intake3 where 1; $allowed_fields = array('Site', 'MedRec', 'Fname', 'Lname', 'Phone', 'Sex', 'Height'); foreach ( $allowed_fields AS $field = $_POST['field']) { if ( ! empty( $_POST['field'] ) ) { $query .= AND '$field' = '$_POST[$field]' ; echo $query; } } This is the value of $_POST: Array ( [Site] = AA [MedRec] = 1 [Fname] = [Lname] = [Phone] = [Height] = [welcome_already_seen] = already_seen ) I receive the following errors on run: Notice: Undefined offset: 0 in /var/www/srchrhsptl4.php on line 135 select * from Intake3 where 1 AND '0' = '' Notice: Undefined offset: 1 in /var/www/srchrhsptl4.php on line 135 select * from Intake3 where 1 AND '0' = '' AND '1' = '' Notice: Undefined offset: 2 in /var/www/srchrhsptl4.php on line 135 select * from Intake3 where 1 AND '0' = '' AND '1' = '' AND '2' = '' Advice and help please. Thanks. Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problem w/query - again
At 12:13 AM 2/10/2012, Amit Tandon wrote: Dear Ethan It seems you are trying to build a query.But you are not getting field names. If you required field names then change the following line to foreach ( $allowed_fields AS $field = $_POST['field']) to foreach ( $allowed_fields AS $field) This would convert the variable field to value. In yoyr line the variable field is treated as array index regds amit The difference between fiction and reality? Fiction has to make sense. snip Advice and help please. Thanks. Ethan PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Amit - Thanks. Tried it. Still does not work. This is the query I get: select * from Intake3 where 1 Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problem w/query - again
Dear Ethan The line you are getting is because the $_POST[fieldname] is blank. So for the following line if ( ! empty( $_POST['field'] ) ) change it to if ( ! empty( $_POST[$field] ) ) Your line : Program is searxchinbg for variable name field New line : The Program is seacging for varable stored in $field. Rember to use double quotes And to verify the value echo $_POST[$field] before your if line i.e. if ( ! empty( $_POST[$field] ) ) regds amit The difference between fiction and reality? Fiction has to make sense. On Fri, Feb 10, 2012 at 11:04 AM, Ethan Rosenberg eth...@earthlink.netwrote: At 12:13 AM 2/10/2012, Amit Tandon wrote: Dear Ethan It seems you are trying to build a query.But you are not getting field names. If you required field names then change the following line to foreach ( $allowed_fields AS $field = $_POST['field']) to foreach ( $allowed_fields AS $field) This would convert the variable field to value. In yoyr line the variable field is treated as array index regds amit The difference between fiction and reality? Fiction has to make sense. snip Advice and help please. Thanks. Ethan PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Amit - Thanks. Tried it. Still does not work. This is the query I get: select * from Intake3 where 1 Ethan
Re: [PHP-DB] Problem w/query - again
At 12:48 AM 2/10/2012, Amit Tandon wrote: Dear Ethan The line you are getting is because the $_POST[fieldname] is blank. So for the following line  if ( ! empty( $_POST['field'] ) ) change it to  if ( ! empty( $_POST[$field] ) ) Your line : Program is searxchinbg for variable name field New line : The Program is seacging for varable stored in $field. Rember to use double quotes And to verify the value echo $_POST[$field] before your if line i.e.  if ( ! empty( $_POST[$field] ) )    regds amit The difference between fiction and reality? Fiction has to make sense. On Fri, Feb 10, 2012 at 11:04 AM, Ethan Rosenberg mailto:eth...@earthlink.neteth...@earthlink.net wrote: At 12:13 AM 2/10/2012, Amit Tandon wrote: Dear Ethan It seems you are trying to build a query.But you are not getting field names. If you required field names then change the following line to foreach ( $allowed_fields AS $field = $_POST['field']) to foreach ( $allowed_fields AS $field) This would convert the variable field to value. In yoyr line the variable field is treated as array index regds amit The difference between fiction and reality? Fiction has to make sense. snip Advice and help please. Thanks. Ethan PHP Database Mailing List (http://www.php.net/http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phphttp://www.php.net/unsub.php Amit - Thanks. Tried your edit. Still does not work. Ethan Amit - Thanks. Tried it.  Still does not work. This is the query I get: select * from Intake3 where  1 Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problem w/query - again - CORRECTION
At 12:48 AM 2/10/2012, Amit Tandon wrote: Dear Ethan The line you are getting is because the $_POST[fieldname] is blank. So for the following line  if ( ! empty( $_POST['field'] ) ) change it to  if ( ! empty( $_POST[$field] ) ) Your line : Program is searxchinbg for variable name field New line : The Program is seacging for varable stored in $field. Rember to use double quotes And to verify the value echo $_POST[$field] before your if line i.e.  if ( ! empty( $_POST[$field] ) )    regds amit The difference between fiction and reality? Fiction has to make sense. On Fri, Feb 10, 2012 at 11:04 AM, Ethan Rosenberg mailto:eth...@earthlink.neteth...@earthlink.net wrote: At 12:13 AM 2/10/2012, Amit Tandon wrote: Dear Ethan It seems you are trying to build a query.But you are not getting field names. If you required field names then change the following line to foreach ( $allowed_fields AS $field = $_POST['field']) to foreach ( $allowed_fields AS $field) This would convert the variable field to value. In yoyr line the variable field is treated as array index regds amit The difference between fiction and reality? Fiction has to make sense. snip Advice and help please. Thanks. Ethan PHP Database Mailing List (http://www.php.net/http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phphttp://www.php.net/unsub.php Amit - Thanks. Tried your edit. Still does not work. Ethan Amit - Thanks. Tried it.  Still does not work. This is the query I get: select * from Intake3 where  1 Ethan - Amit - SORRY. Works Perfectly I had commented out my output routine!! Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php