Re: [PHP] Parse error: parse error, expecting `']'' in
Richard Lynch is quoted as saying on 12/1/2004 2:57 PM: Robert Sossomon wrote: Parse error: parse error, expecting `']'' in file.php SNIP Unfortunately?? I knew exactly where the code was breaking (the lines I posted) since before I added those lines of code the script worked without any problems. But what I don't understand is why sometimes '$_POST[variable]' works and why sometimes it will only work when it is '$_POST['variable']' . Even through my reading and examples I see it both ways, so anyone able to give me a direction to go with it? I am thinking of just changing my coding to put it the second way, but...??? Thanks, Robert -- Robert Sossomon, Business and Technology Application Technician 4-H Youth Development Department 200 Ricks Hall, Campus Box 7606 N.C. State University Raleigh NC 27695-7606 Phone: 919/515-8474 Fax: 919/515-7812 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error: parse error, expecting `']'' in
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm On 01 December 2004 19:29, Matthew Sims wrote: So when using arrays with string keys within strings you need to concatenate it. $var = I live in the city of . $_POST['cityname']; No, you do not *need* to -- it is one option, certainly, but there is no necessity about it. Within double-quoted strings, it is perfectly acceptable to use unquoted array keys: $var = I live in the city of $_POST[cityname]; If you prefer to quote your keys, or have more complex expressions within the brackets, there is also the {} syntax: $var = I live in the city of {$_POST['cityname']}; $field = 'city'; $var = I live in the $field of {$_POST[$field.'name']}; Anyway, read up on it. http://uk.php.net/manual/en/language.types.string.php#language.types.string. parsing Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error: parse error, expecting `']'' in
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm On 02 December 2004 16:49, Matthew Sims wrote: So when using arrays with string keys within strings you need to concatenate it. $var = I live in the city of . $_POST['cityname']; No, you do not *need* to -- it is one option, certainly, but there is no necessity about it. Within double-quoted strings, it is perfectly acceptable to use unquoted array keys: $var = I live in the city of $_POST[cityname]; True and that is perfectly fine though PHP will check to see if cityname is a defined word first. No it will not -- not in a double-quoted string (if by defined word you mean constant). Outside of a double-quoted string, yes it will. As the manuel shows: // Works but note that this works differently outside string-quotes echo A banana is $fruits[banana].; Yes -- *works*, as in always works, because no constant lookup is done when interpolating within a double-quoted string. Consistency can go a long way. :) Oh, I agree with you there, which is why I personally always use the ...{$arr['index']} ... syntax. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error: parse error, expecting `']'' in
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm On 02 December 2004 13:22, Robert Sossomon wrote: But what I don't understand is why sometimes '$_POST[variable]' works and why sometimes it will only work when it is '$_POST['variable']' . Even through my reading and examples I see it both ways, so anyone able to give me a direction to go with it? I am thinking of just changing my coding to put it the second way, but...??? It's valid to put unquoted array subscripts inside a double-quoted string; it's not valid anywhere else. Look at the comment at the start of the second example at http://uk.php.net/manual/en/language.types.string.php#language.types.string. parsing.simple for the official position on this. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error: parse error, expecting `']'' in
So when using arrays with string keys within strings you need to concatenate it. $var = I live in the city of . $_POST['cityname']; No, you do not *need* to -- it is one option, certainly, but there is no necessity about it. Within double-quoted strings, it is perfectly acceptable to use unquoted array keys: $var = I live in the city of $_POST[cityname]; True and that is perfectly fine though PHP will check to see if cityname is a defined word first. And for all consistencies within your script it can be helpful if you use $_POST[cityname] as a define worded array and $_POST['cityname'] as a string keyed array and keep that seperated if ever someone else were to look through your code. As the manuel shows: // Works but note that this works differently outside string-quotes echo A banana is $fruits[banana].; // Works echo A banana is . $fruits['banana'] . .; Consistency can go a long way. :) You are right about the complex syntax. -- --Matthew Sims --http://killermookie.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parse error: parse error, expecting `']'' in
Parse error: parse error, expecting `']'' in file.php I've been working on this script, and can't see why it fails here, but I have another page that uses the same coding and it works correctly. OK, here's the code: $cart1 = ; $cart1 = '$_POST[nutrition_program_assistant]','$_POST[County]','$_POST[ERS_entry_d ate]','$_POST[ERS_exit_date]','$_POST[Group_ID]','$_POST[wname_of_group]','$ _POST[select]','$_POST[Contact_person]','$_POST[Telephone]','$_POST[Group_Ad dress]','$_POST[city]','$_POST[zip]','$_POST[Volunteer_1]','$_POST[Volunteer _2]','$_POST[Volunteer_3]','$_POST[Volunteer_4]','$_POST[Program_start_date] ','$_POST[Projected_end_date]','$_POST[Actual_end_date]','$_POST[Eval_Pre_te st]','$_POST[Eval_post_test]','$_POST[number_meetings]','$_POST[number_conta ct_hours]','$_POST[wname_1]','$_POST[sex_1]','$_POST[race_1]','$_POST[res_1] ','$_POST[bday_mo_1]','$_POST[bday_day_1]','$_POST[bday_yr_1]','$_POST[grade _1]','$_POST[4_h_1]','$_POST[wname_2]','$_POST[sex_2]','$_POST[race_2]','$_P OST[res_2]','$_POST[bday_mo_2]','$_POST[bday_day_2]','$_POST[bday_yr_2]','$_ POST[grade_2]','$_POST[4_h_2]','$_POST[wname_3]','$_POST[sex_3]','$_POST[rac e_3]','$_POST[res_3]','$_POST[bday_mo_3]','$_POST[bday_day_3]','$_POST[bday_ yr _3]','$_POST[grade_3]','$_POST[4_h_3]','$_POST[wname_4]','$_POST[sex_4]','$ _POST[race_4]','$_POST[res_4]','$_POST[bday_mo_4]','$_POST[bday_day_4]','$_P OST[bday_yr_4]','$_POST[grade_4]','$_POST[4_h_4]','$_POST[wname_5]','$_POST[ sex_5]','$_POST[race_5]','$_POST[res_5]','$_POST[bday_mo_5]','$_POST[bday_da y_5]','$_POST[bday_yr_5]','$_POST[grade_5]','$_POST[4_h_5]','$_POST[wname_6] ','$_POST[sex_6]','$_POST[race_6]','$_POST[res_6]','$_POST[bday_mo_6]','$_PO ST[bday_day_6]','$_POST[bday_yr_6]'; $cart2 = ; $cart2 = '$_POST[grade_6]','$_POST[4_h_6]','$_POST[wname_7]','$_POST[sex_7]','$_POS T[race_7]','$_POST[res_7]','$_POST[bday_mo_7]','$_POST[bday_day_7]','$_POST[ bday_yr_7]','$_POST[grade_7]','$_POST[4_h_7]','$_POST[wname_8]','$_POST[sex_ 8]','$_POST[race_8]','$_POST[res_8]','$_POST[bday_mo_8]','$_POST[bday_day_8] ','$_POST[bday_yr_8]','$_POST[grade_8]','$_POST[4_h_8]','$_POST[wname_9]','$ _POST[sex_9]','$_POST[race_9]','$_POST[res_9]','$_POST[bday_mo_9]','$_POST[b day_day_9]','$_POST[bday_yr_9]','$_POST[grade_9]','$_POST[4_h_9]','$_POST[wn ame_10]','$_POST[sex_10]','$_POST[race_10]','$_POST[res_10]','$_POST[bday_mo _10]','$_POST[bday_day_10]','$_POST[bday_yr_10]','$_POST[grade_10]','$_POST[ 4_h_10]','$_POST[Attend_1_1]','$_POST[Attend_2_1]','$_POST[Attend_3_1]','$_P OST[Attend_4_1]','$_POST[Attend_5_1]','$_POST[Attend_6_1]','$_POST[Attend_7_ 1]','$_POST[Attend_8_1]','$_POST[Attend_9_1]','$_POST[Attend_10_1]','$_POST[ Attend_1_2]','$_POST[Attend_2_2]','$_POST[Attend_3_2]','$_POST[Attend_4_2]', '$ _POST[Attend_5_2]','$_POST[Attend_6_2]','$_POST[Attend_7_2]','$_POST[Attend _8_2]','$_POST[Attend_9_2]','$_POST[Attend_10_2]','$_POST[Attend_1_3]','$_PO ST[Attend_2_3]','$_POST[Attend_3_3]','$_POST[Attend_4_3]','$_POST[Attend_5_3 ]','$_POST[Attend_6_3]','$_POST[Attend_7_3]','$_POST[Attend_8_3]','$_POST[At tend_9_3]','$_POST[Attend_10_3]','$_POST[Attend_1_4]','$_POST[Attend_2_4]',' $_POST[Attend_3_4]','$_POST[Attend_4_4]','$_POST[Attend_5_4]','$_POST[Attend _6_4]','$_POST[Attend_7_4]','$_POST[Attend_8_4]','$_POST[Attend_9_4]','$_POS T[Attend_10_4]','$_POST[Attend_1_5]','$_POST[Attend_2_5]','$_POST[Attend_3_5 ]','$_POST[Attend_4_5]','$_POST[Attend_5_5]','$_POST[Attend_6_5]','$_POST[At tend_7_5]','$_POST[Attend_8_5]','$_POST[Attend_9_5]','$_POST[Attend_10_5]',' $_POST[Attend_1_6]','$_POST[Attend_2_6]','$_POST[Attend_3_6]','$_POST[Attend _4_6]','$_POST[Attend_5_6]','$_POST[Attend_6_6]','$_POST[Attend_7_6]','$_POS T[Attend_8_6]','$_POST[Attend_9_6]','$_POST[Attend_10_6]','$_POST[Attend_1_7 ]', '$_POST[Attend_2_7]','$_POST[Attend_3_7]','$_POST[Attend_4_7]','$_POST[Atte nd_5_7]','$_POST[Attend_6_7]','$_POST[Attend_7_7]','$_POST[Attend_8_7]','$_P OST[Attend_9_7]','$_POST[Attend_10_7]','$_POST[Attend_1_8]','$_POST[Attend_2 _8]','$_POST[Attend_3_8]','$_POST[Attend_4_8]','$_POST[Attend_5_8]','$_POST[ Attend_6_8]','$_POST[Attend_7_8]','$_POST[Attend_8_8]','$_POST[Attend_9_8]', '$_POST[Attend_10_8]','$_POST[Attend_1_9]','$_POST[Attend_2_9]','$_POST[Atte nd_3_9]','$_POST[Attend_4_9]','$_POST[Attend_5_9]','$_POST[Attend_6_9]','$_P OST[Attend_7_9]','$_POST[Attend_8_9]','$_POST[Attend_9_9]','$_POST[Attend_10 _9]','$_POST[Attend_1_10]','$_POST[Attend_2_10]','$_POST[Attend_3_10]','$_PO ST[Attend_4_10]','$_POST[Attend_5_10]','$_POST[Attend_6_10]','$_POST[Attend_ 7_10]','$_POST[Attend_8_10]','$_POST[Attend_9_10]','$_POST[Attend_10_10]','$ _POST[TE_CT_1]','$_POST[TE_CTL_1]','$_POST[TE_CT_2]','$_POST[TE_CTL_2]','$_P OST[TE_CT_3]','$_POST[TE_CTL_3]','$_POST[TE_D_1]','$_POST[TE_LT_1]','$_POST[ TE_ A_1]','$_POST[TE_FA_1]','$_POST[TE_H_1]'; $cart3 = ; $cart3 = '$_POST[TE_D_2]','$_POST[TE_LT_2]','$_POST[TE_A_2]','$_POST[TE_FA_2]','$_P OST[TE_H_2]','$_POST[TE_D_3]','$_POST[TE_LT_3]','$_POST[TE_A_3]','$_POST[TE_
Re: [PHP] Parse error: parse error, expecting `']'' in
Parse error: parse error, expecting `']'' in file.php I've been working on this script, and can't see why it fails here, but I have another page that uses the same coding and it works correctly. OK, here's the code: $cart1 = ; $cart1 = '$_POST[nutrition_program_assistant]','$_POST[County]','$_POST[ERS_entry_date]','$_POST[ERS_exit_date]','$_POST[Group_ID]','$_POST[wname_of_group]','$_POST[select]','$_POST[Contact_person]','$_POST[Telephone]','$_POST[Group_Address]','$_POST[city]','$_POST[zip]','$_POST[Volunteer_1]','$_POST[Volunteer_2]','$_POST[Volunteer_3]','$_POST[Volunteer_4]','$_POST[Program_start_date]','$_POST[Projected_end_date]','$_POST[Actual_end_date]','$_POST[Eval_Pre_test]','$_POST[Eval_post_test]','$_POST[number_meetings]','$_POST[number_contact_hours]','$_POST[wname_1]','$_POST[sex_1]','$_POST[race_1]','$_POST[res_1]','$_POST[bday_mo_1]','$_POST[bday_day_1]','$_POST[bday_yr_1]','$_POST[grade_1]','$_POST[4_h_1]','$_POST[wname_2]','$_POST[sex_2]','$_POST[race_2]','$_POST[res_2]','$_POST[bday_mo_2]','$_POST[bday_day_2]','$_POST[bday_yr_2]','$_POST[grade_2]','$_POST[4_h_2]','$_POST[wname_3]','$_POST[sex_3]','$_POST[race_3]','$_POST[res_3]','$_POST[bday_mo_3]','$_POST[bday_day_3]','$_POST[bday_yr _3]','$_POST[grade_3]','$_POST[4_h_3]','$_POST[wname_4]','$_POST[sex_4]','$_POST[race_4]','$_POST[res_4]','$_POST[bday_mo_4]','$_POST[bday_day_4]','$_POST[bday_yr_4]','$_POST[grade_4]','$_POST[4_h_4]','$_POST[wname_5]','$_POST[sex_5]','$_POST[race_5]','$_POST[res_5]','$_POST[bday_mo_5]','$_POST[bday_day_5]','$_POST[bday_yr_5]','$_POST[grade_5]','$_POST[4_h_5]','$_POST[wname_6]','$_POST[sex_6]','$_POST[race_6]','$_POST[res_6]','$_POST[bday_mo_6]','$_POST[bday_day_6]','$_POST[bday_yr_6]'; $cart2 = ; $cart2 = '$_POST[grade_6]','$_POST[4_h_6]','$_POST[wname_7]','$_POST[sex_7]','$_POST[race_7]','$_POST[res_7]','$_POST[bday_mo_7]','$_POST[bday_day_7]','$_POST[bday_yr_7]','$_POST[grade_7]','$_POST[4_h_7]','$_POST[wname_8]','$_POST[sex_8]','$_POST[race_8]','$_POST[res_8]','$_POST[bday_mo_8]','$_POST[bday_day_8]','$_POST[bday_yr_8]','$_POST[grade_8]','$_POST[4_h_8]','$_POST[wname_9]','$_POST[sex_9]','$_POST[race_9]','$_POST[res_9]','$_POST[bday_mo_9]','$_POST[bday_day_9]','$_POST[bday_yr_9]','$_POST[grade_9]','$_POST[4_h_9]','$_POST[wname_10]','$_POST[sex_10]','$_POST[race_10]','$_POST[res_10]','$_POST[bday_mo_10]','$_POST[bday_day_10]','$_POST[bday_yr_10]','$_POST[grade_10]','$_POST[4_h_10]','$_POST[Attend_1_1]','$_POST[Attend_2_1]','$_POST[Attend_3_1]','$_POST[Attend_4_1]','$_POST[Attend_5_1]','$_POST[Attend_6_1]','$_POST[Attend_7_1]','$_POST[Attend_8_1]','$_POST[Attend_9_1]','$_POST[Attend_10_1]','$_POST[Attend_1_2]','$_POST[Attend_2_2]','$_POST[Attend_3_2]','$_POST[Attend_4_2]','$ _POST[Attend_5_2]','$_POST[Attend_6_2]','$_POST[Attend_7_2]','$_POST[Attend_8_2]','$_POST[Attend_9_2]','$_POST[Attend_10_2]','$_POST[Attend_1_3]','$_POST[Attend_2_3]','$_POST[Attend_3_3]','$_POST[Attend_4_3]','$_POST[Attend_5_3]','$_POST[Attend_6_3]','$_POST[Attend_7_3]','$_POST[Attend_8_3]','$_POST[Attend_9_3]','$_POST[Attend_10_3]','$_POST[Attend_1_4]','$_POST[Attend_2_4]','$_POST[Attend_3_4]','$_POST[Attend_4_4]','$_POST[Attend_5_4]','$_POST[Attend_6_4]','$_POST[Attend_7_4]','$_POST[Attend_8_4]','$_POST[Attend_9_4]','$_POST[Attend_10_4]','$_POST[Attend_1_5]','$_POST[Attend_2_5]','$_POST[Attend_3_5]','$_POST[Attend_4_5]','$_POST[Attend_5_5]','$_POST[Attend_6_5]','$_POST[Attend_7_5]','$_POST[Attend_8_5]','$_POST[Attend_9_5]','$_POST[Attend_10_5]','$_POST[Attend_1_6]','$_POST[Attend_2_6]','$_POST[Attend_3_6]','$_POST[Attend_4_6]','$_POST[Attend_5_6]','$_POST[Attend_6_6]','$_POST[Attend_7_6]','$_POST[Attend_8_6]','$_POST[Attend_9_6]','$_POST[Attend_10_6]','$_POST[Attend_1_7]', '$_POST[Attend_2_7]','$_POST[Attend_3_7]','$_POST[Attend_4_7]','$_POST[Attend_5_7]','$_POST[Attend_6_7]','$_POST[Attend_7_7]','$_POST[Attend_8_7]','$_POST[Attend_9_7]','$_POST[Attend_10_7]','$_POST[Attend_1_8]','$_POST[Attend_2_8]','$_POST[Attend_3_8]','$_POST[Attend_4_8]','$_POST[Attend_5_8]','$_POST[Attend_6_8]','$_POST[Attend_7_8]','$_POST[Attend_8_8]','$_POST[Attend_9_8]','$_POST[Attend_10_8]','$_POST[Attend_1_9]','$_POST[Attend_2_9]','$_POST[Attend_3_9]','$_POST[Attend_4_9]','$_POST[Attend_5_9]','$_POST[Attend_6_9]','$_POST[Attend_7_9]','$_POST[Attend_8_9]','$_POST[Attend_9_9]','$_POST[Attend_10_9]','$_POST[Attend_1_10]','$_POST[Attend_2_10]','$_POST[Attend_3_10]','$_POST[Attend_4_10]','$_POST[Attend_5_10]','$_POST[Attend_6_10]','$_POST[Attend_7_10]','$_POST[Attend_8_10]','$_POST[Attend_9_10]','$_POST[Attend_10_10]','$_POST[TE_CT_1]','$_POST[TE_CTL_1]','$_POST[TE_CT_2]','$_POST[TE_CTL_2]','$_POST[TE_CT_3]','$_POST[TE_CTL_3]','$_POST[TE_D_1]','$_POST[TE_LT_1]','$_POST[TE_ A_1]','$_POST[TE_FA_1]','$_POST[TE_H_1]'; $cart3 = ; $cart3 =
Re: [PHP] Parse error: parse error, expecting `']'' in
Robert Sossomon wrote: Parse error: parse error, expecting `']'' in file.php First, some minor nits with other posters :-) 1. While it's true that integer and string keys are handled differently in some cases, it has absolutely no bearing when the array reference is buried in a string. 2. The code formatting provided by another poster doesn't seem all that better to me than the original. YMMV. Then, a minor nit with the original poster: Dude, you chopped out the line number from the error message. That would pretty much have made it possible to determine what was going wrong, maybe. You probably left out a ']' somewhere, which is exactly what PHP is complaining about. It's also possible a missing quote or apostrophe in an EARLIER line is the real problem, and the code you posted, on its own, is 100% correct. Finally, to all newbie PHP coders. If syntax errors are giving you problems, then get a color-coding editor, or plug-in for the editor you are using. I'm too old to change my ways and use one, but I'm long past the day of wondering what any given syntax error could mean. :-) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php