Jump to content

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/6974-php-form-processing/
Share on other sites

[!--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]
Link to comment
https://forums.phpfreaks.com/topic/6974-php-form-processing/#findComment-25343
Share on other sites

[!--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)
Link to comment
https://forums.phpfreaks.com/topic/6974-php-form-processing/#findComment-25347
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.