Jump to content

Archived

This topic is now archived and is closed to further replies.

Grant Aasland

PHP form processing

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]

Share this post


Link to post
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]

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

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.