Page 1 of 1

Please help with my code [Form submission]

Posted: Thu Jul 09, 2009 8:06 pm
by gimpact
Hello,
I am trying to retrieve form submission in PHP class. I am unable to retrieve any thing. Please tell me where I am going wrong.

HTML form:

Code: Select all

<form action="inc/Index.php" method="POST">
            firstname:<input type="text" name="firstname" value="" />
            <br>
            lastname:<input type="text" name="lastname" value="" />
            <br>
            Email:<input type="text" name="email1" value="" />
            <br>
            Email:<input type="text" name="email2" value="" />
            <br>
            Password:<input type="text" name="password1" value="" />
            <br>
            Password:<input type="text" name="password2" value="" />
            <br>
            <input type="submit" value="" />
        </form>

Code: Select all

<?php
 
include "DBConnection.php";
 
class Index {
    // Main() method
    function Index(){
        if(ISSET($_POST['SUBMIT'])){
            $firstname = stripslashes($_POST['firstname']);
            $lastname = stripslashes($_POST['lastname']);
            $email1 = striplashes($_POST['email1']);
            $email2 = stripslashes($_POST['email2']);
            $password1 = stripslashes($_POST['password1']);
            $password2 = stripslashes($_POST['password2']);
 
            // Check for empty values
            if(empty($_POST['firstname'])){ header("Location: ../index.php?error=firstname"); exit(); }
            if(empty($_POST['lastname'])){ header("Location: ../index.php?error=lastname");exit(); }
            if(empty($_POST['email1'])){ header("Location: ../index.php?error=email");exit(); }
            if(empty($_POST['email2'])){ header("Location: ../index.php?error=email");exit(); }
            if(empty($_POST['password1'])){ header("Location: ../index.php?error=password");exit(); }
            if(empty($_POST['password2'])){ header("Location: ../index.php?error=password");exit(); }
 
            // Check for similarity
            if($email1 != $email2){ header("Location: ../index.php?error=emailMissMatch"); exit(); }
            if($password1 != $password2){ header("Location: ../index.php?error=passwordMissMatch"); exit(); }
            /*
            // Database connection operation
            $dbConnection = new DBConnection;
            $dbConnection -> DBConnection();
 
            // MySQL Operation
            $sql_answer = mysql_query("select * from userdata where email = '".$email1."'");
            $sql_row = mysql_num_rows($sql_answer);
 
            // Check user exist/dont exist
            if($sql_row > 0){
                header("Location: http://www.x.com/login/index.php?value=userExist");
                exit();
            }
            */
            // Generate random number
            $random_number = rand(000000000, 999999999);
            print $random_number;
            /*
            // Send email
            $email = new Email;
            $email ->Email($email1, $random_number);
            */
 
        }else{
                header("Location: ../index.php");
            }
        //
 
    } // end of fuction index()
}
?>
Thank you,

Re: Please help with my code [Form submission]

Posted: Thu Jul 09, 2009 9:34 pm
by weiyangyang
gimpact wrote:Hello,
I am trying to retrieve form submission in PHP class. I am unable to retrieve any thing. Please tell me where I am going wrong.

HTML form:

Code: Select all

<form action[color=#FF0000]="inc/Index.php"[/color] method="POST">
            firstname:<input type="text" name="firstname" value="" />
            <br>
            lastname:<input type="text" name="lastname" value="" />
            <br>
            Email:<input type="text" name="email1" value="" />
            <br>
            Email:<input type="text" name="email2" value="" />
            <br>
            Password:<input type="text" name="password1" value="" />
            <br>
            Password:<input type="text" name="password2" value="" />
            <br>
            <input type="submit" value="" />
        </form>

Code: Select all

<?php
 
include "DBConnection.php";
 
class Index {
    // Main() method
    function Index(){
        if(ISSET($_POST['SUBMIT'])){
            $firstname = stripslashes($_POST['firstname']);
            $lastname = stripslashes($_POST['lastname']);
            $email1 = striplashes($_POST['email1']);
            $email2 = stripslashes($_POST['email2']);
            $password1 = stripslashes($_POST['password1']);
            $password2 = stripslashes($_POST['password2']);
 
            // Check for empty values
            if(empty($_POST['firstname'])){ header("Location: ../index.php?error=firstname"); exit(); }
            if(empty($_POST['lastname'])){ header("Location: ../index.php?error=lastname");exit(); }
            if(empty($_POST['email1'])){ header("Location: ../index.php?error=email");exit(); }
            if(empty($_POST['email2'])){ header("Location: ../index.php?error=email");exit(); }
            if(empty($_POST['password1'])){ header("Location: ../index.php?error=password");exit(); }
            if(empty($_POST['password2'])){ header("Location: ../index.php?error=password");exit(); }
 
            // Check for similarity
            if($email1 != $email2){ header("Location: ../index.php?error=emailMissMatch"); exit(); }
            if($password1 != $password2){ header("Location: ../index.php?error=passwordMissMatch"); exit(); }
            /*
            // Database connection operation
            $dbConnection = new DBConnection;
            $dbConnection -> DBConnection();
 
            // MySQL Operation
            $sql_answer = mysql_query("select * from userdata where email = '".$email1."'");
            $sql_row = mysql_num_rows($sql_answer);
 
            // Check user exist/dont exist
            if($sql_row > 0){
                header("Location: http://www.x.com/login/index.php?value=userExist");
                exit();
            }
            */
            // Generate random number
            $random_number = rand(000000000, 999999999);
            print $random_number;
            /*
            // Send email
            $email = new Email;
            $email ->Email($email1, $random_number);
            */
 
        }else{
                header("Location: ../index.php");
            }
        //
 
    } // end of fuction index()
}
?>
Thank you,
check code in red

Re: Please help with my code [Form submission]

Posted: Thu Jul 09, 2009 11:02 pm
by califdon
I don't see that you ever instantiate the Index class. A class is merely a template or recipe. Nothing happens until you declare an instance of the class, like:

Code: Select all

$myIndex = New Index;

Re: Please help with my code [Form submission]

Posted: Fri Jul 10, 2009 3:57 am
by gimpact
Hi,
Thanks for replying. Why do you think i need to instantiate my Index class when every thing is being done with in that class. I have the form which when submitted sends the value to Index class and with in index class I have every thing being done.

By the way, you really think i need to instantiate Index class please tell me how?

Re: Please help with my code [Form submission]

Posted: Fri Jul 10, 2009 4:09 am
by SvanteH
I'm just thinking, isn't $_POST case sensitive so when you're checking for

Code: Select all

if(ISSET($_POST['SUBMIT'])){
it obviously wouldn't work if that's the case.