Page 1 of 1

cant use post or get action to get data from html page

Posted: Mon Mar 05, 2012 11:51 am
by eoin.ahern@mycit.ie
i have a very basic set up here a html page with some php on my server with two input boxes to take in a email and password and a submit button when i try and submit the data i dont seem to be getting anything back when using "get" or "post" in the html form action. i have tryed method ="<?=$_SERVER['PHP_SELF'];?>" as the method and method ="" and neither work. here is my code for the index. i basically need the data inputed by the user to do anything with the class so far i havent been able to grab the data entered at all.




<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>

<form action="get" method="">
<label for="email">enter email</label>
<input type="text" id="email" name="email" /><br />
<label for="password">enter password</label>
<input type="text" id="password" name="password"/><br />
<input type="submit" value="submitbutton" name="submit" />
</form>

<?php

include("userdetails.php"); //this is a class
if(isset($_GET['submit']))
{
session_start();
$user = new userdetails();
$name = $user->getname();
echo $name;
}
?>

</body>
</html>





here is some of my userdetails.php class, the parts that im using so far, obviously i hope to do a lot more with it.





<?php

class userdetails {
private $email;
private $password;

public function __construct() {
$this->email = $_GET['email'];
$this->password =$_GET['password'];
}

public function getname()
{
if(isset($this->email))
{
return $this->email;
}
else
{
return "notset";
}
}
}
?>





anyway thanks for all the help you can give me ive been stuck on this for a while now if i cant get this im not going to pass this project unfortunately . its doing my head in! :banghead:

Re: cant use post or get action to get data from html page

Posted: Mon Mar 05, 2012 11:54 am
by Celauran
Here's the problem:

Code: Select all

<form action="get" method="">
You seem to have your action and method backwards. This is probably what you want:

Code: Select all

<form action="script_that_processes_form.php" method="post">

Re: cant use post or get action to get data from html page

Posted: Mon Mar 05, 2012 12:11 pm
by eoin.ahern@mycit.ie
okay thanks, that was an ameteur mistake! im still conviced it wont work though! ha ha!

Re: cant use post or get action to get data from html page

Posted: Mon Mar 05, 2012 12:16 pm
by eoin.ahern@mycit.ie
it worked thank f***! thanks very much, you are a life saver!! :mrgreen: