action php code not invoked

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

action php code not invoked

Post by lipun4u »

I am trying to learn php.

Now consider the following code. (file name is jobapp.php)

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body>
    <?php
        require("common.php");
    ?>
    <h1><?php echo(COMPANY); ?> Job Application</h1>
    <p>Are you looking to get <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> ??"</p>
    <form name="frmJobApp" method="post" action="jobapp_action.php">
        Please enter ur name : 
        <input name="applicant" type="text" /><br />
        Please enter ur telephone number :
        <input name="phone" type="text" /><br />
        Please enter ur e-mail id : 
        <input name="email" type="text" /><br />
        Please select the type of position in which you are interested :
        <select name="position">
            <option value="a">Accounting</option>
            <option value="h">Human resource</option>
            <option value="m">Management</option>
            <option value="s">Sales</option>
        </select><br />
        Please select the country in which you would like to work : 
        <select name="country">
            <option value="ca">Canada</option>
            <option value="cr">Costa Rica</option>
            <option value="uk">United Kingdom</option>
            <option value="ge">Germany</option>
            <option value="us">United States</option>
        </select><br />
        <input name="avail" type="checkbox" />Available immediately <br />
        <input name="enter" type="submit" value="Enter" />
    </form>
</body>
</html>
Now consider the following code.(file name is jobapp_action.php)

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body>
    <?php
        require("common.php");
        echo("<B>You have submitted the following </b>"
                NL . NL .
                "NAME : $applicant" . NL .
                "PHONE : $phone" . NL .
                "E-MAIL : $email" .NL);
        $avail = isset($avail);
        echo ("Available immediately : " . ($avail ? "yes" : "no"));
    ?>      
</body>
</html>
 
According 2 me, everything is fine. But why the 2nd php code is not invoked ????
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: action php code not invoked

Post by jackpf »

What do you mean by "not invoked"?

What happens when you submit the form?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: action php code not invoked

Post by John Cartwright »

Code: Select all

<p>Are you looking to get <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> ??"</p>
What kind of job application is this!?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: action php code not invoked

Post by Mark Baker »

You're submitting your form using the post method, so the form fields should be available as (for example) $_POST['applicant'] rather than $applicant
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: action php code not invoked

Post by jackpf »

Oh yeah, didn't notice that. Don't use register globals.
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: action php code not invoked

Post by lipun4u »

now I got this...$_GET[...]
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: action php code not invoked

Post by Mark Baker »

lipun4u wrote:now I got this...$_GET[...]
If you form method is get, then you use $_GET. If your form method is post (as it is in your sample code) then you use $_POST
Post Reply