Page 1 of 1

basic help with form submission code

Posted: Sun Jul 12, 2009 7:58 am
by gimpact
Hi,
I am new to php. I trying out this code and one part of the code does not work. Can some one please tell me why this dont work and why it works when I remove this.
Form page - index.php

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        $option = $_GET['value'];
        if($option == "Option"){
            $display = "You need to select an option";
        }else{
            $display = "";
        }
        ?>
        <br>
        <br>
        <?php
        print $display;
        ?>
        <form action="inc/register.php" method="POST">
            email:<input type="text" name="email" value="" />
            <br>
            password:<input type="text" name="password" value="" />
            <br>
            <select name="attribute">
                Select
                <option>Organization</option>
                <option>Student</option>
            </select>
            <br>
            <input type="SUBMIT" value="SUBMIT" />
        </form>
       
    </body>
</html>
 
Register.php - This works

Code: Select all

<?php 
// Get email
$email = $_REQUEST['email'];
// Get password
$password = $_REQUEST['password'];
// Get attribute
$attribute = $_REQUEST['attribute'];
 
    if($attribute == "Student"){
        print "You selected Student";
    }elseif($attribute == "Organization"){
        print "You selectd Organization";
    }else{
    header("Location: ../index.php?value=Option");
    }
 
 
 
?>
 
This always sends me back to index.php page for registration

Code: Select all

<?php 
if(ISSET($_POST['SUBMIT'])){
 
// Get email
$email = $_REQUEST['email'];
// Get password
$password = $_REQUEST['password'];
// Get attribute
$attribute = $_REQUEST['attribute'];
 
    if($attribute == "Student"){
        print "You selected Student";
    }elseif($attribute == "Organization"){
        print "You selectd Organization";
    }else{
    header("Location: ../index.php?value=Option");
    }
 
}else{
    header("Location: ../index.php");
}
 
?>
 
Thank you

Re: basic help with form submission code

Posted: Sun Jul 12, 2009 11:49 am
by Eric!
if(ISSET($_POST['SUBMIT']))

fails because your submit button is lacking a name="SUBMIT" field like this

Code: Select all

<input type="SUBMIT" name="SUBMIT" value="SUBMIT" />

Re: basic help with form submission code

Posted: Sun Jul 12, 2009 7:05 pm
by gimpact
Thank you

Re: basic help with form submission code

Posted: Sun Jul 12, 2009 8:33 pm
by Eric!
Por nada!