MainStWebGuy Posted September 12, 2011 Share Posted September 12, 2011 Hello everyone, I am trying to get values from some input forms and put them into an array but I'm not getting it. I would like to store some vehicle information that a user enters in a simple for in an array so i can use it in my app, but i think i'm screwing up the syntax... what am i doing wrong? $unit1 = array('Number' => $_POST['unit1'], 'Year' => $_POST['year1'], 'Make' => $_POST['make1'], 'Model' => $_POST['model1'], 'Glass' => $_POST['unit1Glass']); any insight, advice, hysterical comments encouraged and appreciated Quote Link to comment https://forums.phpfreaks.com/topic/246990-help-with-an-array/ Share on other sites More sharing options...
Pikachu2000 Posted September 12, 2011 Share Posted September 12, 2011 What makes you think you're doing something wrong? Is there an error? Quote Link to comment https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268472 Share on other sites More sharing options...
MainStWebGuy Posted September 12, 2011 Author Share Posted September 12, 2011 haha sorry i guess that info would help out... I'm getting an error on the line containing that code snippet "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in...blah blah blah" Quote Link to comment https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268473 Share on other sites More sharing options...
jcbones Posted September 12, 2011 Share Posted September 12, 2011 OK, post your code: from 5 lines above the error, to 5 lines below the error. Quote Link to comment https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268474 Share on other sites More sharing options...
MainStWebGuy Posted September 12, 2011 Author Share Posted September 12, 2011 Sure thing: <?php if(isset($_POST['sendRequest'])) { $fleet = $_POST['fleet']; $contact = $_POST['contact']; $time = $_POST['start_month']." ".$_POST['start_day'].". ".$_POST['start_hour'].":".$_POST['start_minute']." ".$_POST['amPm']; $unit1 = array('Number' => $_POST['unit1'], 'Year' => $_POST['year1'], 'Make' => $_POST['make1'], 'Model' => $_POST['model1'], 'Glass' => $_POST['unit1Glass']); $unit2 = array('Number' => $_POST['unit2'], 'Year' => $_POST['year2'], 'Make' => $_POST['make2'], 'Model' => $_POST['model2'], 'Glass' => $_POST['unit2Glass']); $notes = $_POST['notes']; $msg = "Fleet: $fleet. Contact: $contact\n$unit1['Year'] $unit1['Make'] $unit1['Model'] $unit1['Glass']\n"; if(isset($_POST['unit2']) && $_POST['unit2'] != '') { $msg .= "$unit2['Year'] $unit2['Make'] $unit2['Model'] $unit2['Glass']\n"; } if this isn't enough code, i'd be happy to show whatever else might help. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268476 Share on other sites More sharing options...
Pandemikk Posted September 12, 2011 Share Posted September 12, 2011 Quoted keys don't work in simple syntax. Use curly braces (complex syntax) for those. www.php.net/manual/en/language.types.string.php#language.types.string.parsing <?php $msg = "Fleet: $fleet. Contact: $contact\n{$unit1['Year']} {$unit1['Make']} {$unit1['Model']} {$unit1['Glass']}\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268488 Share on other sites More sharing options...
MainStWebGuy Posted September 13, 2011 Author Share Posted September 13, 2011 Thanks again for the insight on this guys, The last comment did the trick (my syntax was wrong). Quote Link to comment https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.