Results 1 to 2 of 2

Thread: Complicated PHP & Javascript Problem - NEED HELP

  1. #1
    Join Date
    Oct 2010
    Posts
    37

    Complicated PHP & Javascript Problem - NEED HELP

    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();

    ?>

  2. #2
    Join Date
    Mar 2007
    Location
    Werrington, England
    Posts
    1,315
    $firstname isn't defined. You need to add $this-> so it uses the class variable.

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


Similar Threads

  1. Javascript and PHP problem
    By aljohn03 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 31
    Last Post: 04 Dec 2012, 11:04 PM
  2. PHP & JavaScript Assignment Help Please!
    By airjonny22 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 26 Oct 2009, 03:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •