Jump to content


Photo

PHP form processing


  • Please log in to reply
3 replies to this topic

#1 Grant Aasland

Grant Aasland
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 April 2006 - 09:43 PM

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.

Html Form (cheeseform.php):
<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>

PHP code for processing (cheesefp.php):
<?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";
        }
    }    
?>

This is the error I get when trying to submit the code:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: syntax error, unexpected $end in /cheesefp.php on line 32[/quote]


#2 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 09 April 2006 - 10:44 PM

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]


PHP code for processing (cheesefp.php):
<?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";
        }
    }    
?>

This is the error I get when trying to submit the code:
[/quote]

Try This:
<?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";
        }
    }    
?>


#3 mystxx

mystxx
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 09 April 2006 - 10:53 PM

[!--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) View Post[/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.

Html Form (cheeseform.php):
<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>

PHP code for processing (cheesefp.php):
<?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";
        }
    }    
?>

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)


#4 Grant Aasland

Grant Aasland
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 April 2006 - 11:28 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users