Page 1 of 1

action php code not invoked

Posted: Sun Sep 13, 2009 1:20 pm
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 ????

Re: action php code not invoked

Posted: Sun Sep 13, 2009 1:27 pm
by jackpf
What do you mean by "not invoked"?

What happens when you submit the form?

Re: action php code not invoked

Posted: Sun Sep 13, 2009 1:43 pm
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!?

Re: action php code not invoked

Posted: Sun Sep 13, 2009 1:55 pm
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

Re: action php code not invoked

Posted: Sun Sep 13, 2009 2:12 pm
by jackpf
Oh yeah, didn't notice that. Don't use register globals.

Re: action php code not invoked

Posted: Sun Sep 13, 2009 2:55 pm
by lipun4u
now I got this...$_GET[...]

Re: action php code not invoked

Posted: Mon Sep 14, 2009 4:23 am
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