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

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

Post Reply
eoin.ahern@mycit.ie
Forum Newbie
Posts: 15
Joined: Mon Mar 05, 2012 11:48 am

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

Post 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:
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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">
eoin.ahern@mycit.ie
Forum Newbie
Posts: 15
Joined: Mon Mar 05, 2012 11:48 am

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

Post by eoin.ahern@mycit.ie »

okay thanks, that was an ameteur mistake! im still conviced it wont work though! ha ha!
eoin.ahern@mycit.ie
Forum Newbie
Posts: 15
Joined: Mon Mar 05, 2012 11:48 am

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

Post by eoin.ahern@mycit.ie »

it worked thank f***! thanks very much, you are a life saver!! :mrgreen:
Post Reply