Grant Aasland Posted April 9, 2006 Share Posted April 9, 2006 I'm quite new to php, and I'm currently trying to use PHP to process a form submitted by a user and display result (to the user) depending on the inputed data. I'm not sure how exactly to work with form processing, and my attempt didn't work.This is my code that I was using, if any could show me what I'm doing wrong and how to fix it, I would be most appreciative.[b]Html Form (cheeseform.php):[/b][code]<Html><Head> <Title>SPC</Title></Head><Body bgcolor="8dcff4"><Form action="http://www.--.com/cheesefp.php" method="get"> <B>Do you like cheese?</B><br> <Input type="radio" name="q1" value="1">Yes<br> <Input type="radio" name="q1" value="2">No<br> <Input type="radio" name="q1" value="3">Maybe<br> <br> <B>If you checked yes or maybe above, check all kinds that apply.</B><br> <Input type="checkbox" name="q2a" value="1">Blue<br> <Input type="checkbox" name="q2b" value="2">Cheddar<br> <Input type="checkbox" name="q2c" value="3">Swiss<br> <br><Input type="submit" value="Submit"></Form> </Body></Html>[/code][b]PHP code for processing (cheesefp.php):[/b][code]<?php if ($_GET[q1] == "1") { echo "You like cheese!"; } else if ($_GET[q1] == "2") { echo "You don't like cheese!"; } else if ($_GET[q1] == "3") { echo "You might like cheese!"; }?><?php if ($_GET[q2a] == "1") { if ($_GET[q2b] == "2") { if ($_GET[q2c] == "3") { echo "You like all the cheeses!"; } else { echo "You like Blue, and Cheddar cheese!"; } } else if ($_GET[q2c] == "3") { echo "You like Blue, and Swiss cheese!"; } else if ($_GET[q2a] == "1") { echo "You like Blue cheese!"; } else if ($_GET[q2b] == "2") { if ($_GET[q2c] == "3") { echo "You like Cheddar, and Swiss cheese!"; } else if ($_GET[q2b] == "2") { echo "You like Cheddar cheese!"; } else { echo "Blah"; } } ?>[/code]This is the error I get when trying to submit the code:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--][b]Parse error:[/b] syntax error, unexpected $end in [b]/cheesefp.php[/b] on line [b]32[/b][/quote] Quote Link to comment https://forums.phpfreaks.com/topic/6974-php-form-processing/ Share on other sites More sharing options...
Eugene Posted April 9, 2006 Share Posted April 9, 2006 [!--quoteo(post=363122:date=Apr 9 2006, 05:43 PM:name=Grant Aasland)--][div class=\'quotetop\']QUOTE(Grant Aasland @ Apr 9 2006, 05:43 PM) [snapback]363122[/snapback][/div][div class=\'quotemain\'][!--quotec--][b]PHP code for processing (cheesefp.php):[/b][code]<?php if ($_GET[q1] == "1") { echo "You like cheese!"; } else if ($_GET[q1] == "2") { echo "You don't like cheese!"; } else if ($_GET[q1] == "3") { echo "You might like cheese!"; }?><?php if ($_GET[q2a] == "1") { if ($_GET[q2b] == "2") { if ($_GET[q2c] == "3") { echo "You like all the cheeses!"; } else { echo "You like Blue, and Cheddar cheese!"; } } else if ($_GET[q2c] == "3") { echo "You like Blue, and Swiss cheese!"; } else if ($_GET[q2a] == "1") { echo "You like Blue cheese!"; } else if ($_GET[q2b] == "2") { if ($_GET[q2c] == "3") { echo "You like Cheddar, and Swiss cheese!"; } else if ($_GET[q2b] == "2") { echo "You like Cheddar cheese!"; } else { echo "Blah"; } } ?>[/code]This is the error I get when trying to submit the code:[/quote]Try This:[code]<?php if ($_GET['q1'] == "1") { echo "You like cheese!"; } else if ($_GET['q1'] == "2") { echo "You don't like cheese!"; } else if ($_GET['q1'] == "3") { echo "You might like cheese!"; }?><?php if ($_GET['q2a'] == "1") { if ($_GET['q2b'] == "2") { if ($_GET['q2c'] == "3") { echo "You like all the cheeses!"; } else { echo "You like Blue, and Cheddar cheese!"; } } else if ($_GET['q2c'] == "3") { echo "You like Blue, and Swiss cheese!"; } else if ($_GET['q2a'] == "1") { echo "You like Blue cheese!"; } else if ($_GET['q2b'] == "2") { if ($_GET['q2c'] == "3") { echo "You like Cheddar, and Swiss cheese!"; } else if ($_GET['q2b'] == "2") { echo "You like Cheddar cheese!"; } else { echo "Blah"; } } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6974-php-form-processing/#findComment-25343 Share on other sites More sharing options...
mystxx Posted April 9, 2006 Share Posted April 9, 2006 [!--quoteo(post=363122:date=Apr 9 2006, 04:43 PM:name=Grant Aasland)--][div class=\'quotetop\']QUOTE(Grant Aasland @ Apr 9 2006, 04:43 PM) [snapback]363122[/snapback][/div][div class=\'quotemain\'][!--quotec--]I'm quite new to php, and I'm currently trying to use PHP to process a form submitted by a user and display result (to the user) depending on the inputed data. I'm not sure how exactly to work with form processing, and my attempt didn't work.This is my code that I was using, if any could show me what I'm doing wrong and how to fix it, I would be most appreciative.[b]Html Form (cheeseform.php):[/b][code]<Html><Head> <Title>SPC</Title></Head><Body bgcolor="8dcff4"><Form action="http://www.--.com/cheesefp.php" method="get"> <B>Do you like cheese?</B><br> <Input type="radio" name="q1" value="1">Yes<br> <Input type="radio" name="q1" value="2">No<br> <Input type="radio" name="q1" value="3">Maybe<br> <br> <B>If you checked yes or maybe above, check all kinds that apply.</B><br> <Input type="checkbox" name="q2a" value="1">Blue<br> <Input type="checkbox" name="q2b" value="2">Cheddar<br> <Input type="checkbox" name="q2c" value="3">Swiss<br> <br><Input type="submit" value="Submit"></Form> </Body></Html>[/code][b]PHP code for processing (cheesefp.php):[/b][code]<?php if ($_GET[q1] == "1") { echo "You like cheese!"; } else if ($_GET[q1] == "2") { echo "You don't like cheese!"; } else if ($_GET[q1] == "3") { echo "You might like cheese!"; }?><?php if ($_GET[q2a] == "1") { if ($_GET[q2b] == "2") { if ($_GET[q2c] == "3") { echo "You like all the cheeses!"; } else { echo "You like Blue, and Cheddar cheese!"; } } else if ($_GET[q2c] == "3") { echo "You like Blue, and Swiss cheese!"; } else if ($_GET[q2a] == "1") { echo "You like Blue cheese!"; } else if ($_GET[q2b] == "2") { if ($_GET[q2c] == "3") { echo "You like Cheddar, and Swiss cheese!"; } else if ($_GET[q2b] == "2") { echo "You like Cheddar cheese!"; } else { echo "Blah"; } } ?>[/code]This is the error I get when trying to submit the code:[/quote]You are just missing one more "}" before PHP closing tag -- ?>Just add that.G F D is right. (sorry mate, saw the post too late) Quote Link to comment https://forums.phpfreaks.com/topic/6974-php-form-processing/#findComment-25347 Share on other sites More sharing options...
Grant Aasland Posted April 9, 2006 Author Share Posted April 9, 2006 It looks like I was missing one more } at the end. I was hoping it would be something fairly simple like that. Thanks muchly for the help! Quote Link to comment https://forums.phpfreaks.com/topic/6974-php-form-processing/#findComment-25359 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.