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
gimpact
Forum Commoner
Posts: 65 Joined: Tue Jun 16, 2009 11:08 pm
Post
by gimpact » Thu Jul 09, 2009 8:06 pm
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,
weiyangyang
Forum Newbie
Posts: 1 Joined: Thu Jul 09, 2009 9:23 pm
Post
by weiyangyang » Thu Jul 09, 2009 9:34 pm
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
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Thu Jul 09, 2009 11:02 pm
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:
gimpact
Forum Commoner
Posts: 65 Joined: Tue Jun 16, 2009 11:08 pm
Post
by gimpact » Fri Jul 10, 2009 3:57 am
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?
SvanteH
Forum Commoner
Posts: 50 Joined: Wed Jul 08, 2009 12:25 am
Post
by SvanteH » Fri Jul 10, 2009 4:09 am
I'm just thinking, isn't $_POST case sensitive so when you're checking for
it obviously wouldn't work if that's the case.