PDA

View Full Version : Complicated PHP & Javascript Problem - NEED HELP



jp504
30 Jan 2011, 03:16 PM
I need help getting my code to work. The php script is not working with the html form. I can't tell if i'm supposed to use javascript too. Could anyone please look at the code below and provide a solution to my problem.

HTML FORM:

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

<label id="lblFirstname" for="txtFirstname">Enter your First Name: </label>

<input type="text" id="txtFirstname" name="firstname" tabindex="1" />

<br />

<input type="submit" value="submit" id="btnSubmit" name="submit" tabindex="2" />

</form>



PHP CODE:

<?php
class practice {

public $firstname = $_POST['firstname'];

public function name() {
return( $firstname );
}
}

$obj = new practice();
$obj->name();

?>

Jason
31 Jan 2011, 02:14 AM
$firstname isn't defined. You need to add $this-> so it uses the class variable.



public function name() {
return( $this->firstname );
}
}