Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I am having serious problems with variables. Please Help!

    I am just trying to do something as simple as passing a password to the next page, and it will not work. I am a beginner with php, and the most I can actually do is the print() function... here is the code for form.html
    Code:
    <html>
    <head>
    <title>HTML Form</Title>
    </Head>
    <Body>
    
    <form action="HandleForm.php" Method=GET>
    Password <input type=TEXT Name="Pass"><br>
    <input type=SUBMIT name="SUBMIT">
    </form>
    
    </Body>
    </HTML>
    And here is the code for HandleForm.php:
    Code:
    <?php
    print "Your password was $Pass<br>";
    ?>
    Could anybody tell me what I am doing wrong?????? Please?? Thanks for n e hlp in advance!!
    Oh yeah, this is the error I keep getting:
    Dumb Notice:

    Notice: Undefined variable: Pass in c:\program files\apache group\apache\htdocs\l3vi\handleform.php on line 2
    Last edited by l3vi; 03-11-2003 at 12:16 AM.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    print "Your password was $_GET['Pass']<br>";

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ??? That still doesnt work.

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use $_POST['pass']; instead


    Jason

  • #5
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still doesnt work. It says:
    Notice: Undefined variable: _Post in c:\program files\apache group\apache\htdocs\l3vi\handleform.php on line 2
    Your password was

  • #6
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <?php
    echo "<html><head><title>HTML Form</Title></Head><Body>";
    ?>
    <form action="HandleForm.php" Method="post">

    <?php
    echo "Password ";
    echo ("<input type=TEXT Name="Pass"><br>";
    ?>

    <SCRIPT LANGUAGE="JavaScript">
    document.writeln ( '<input type=SUBMIT name="SUBMIT">');
    </SCRIPT>
    </form>

    <?php
    if (count($_POST > 0)){
    $pass = $_POST['Pass'];
    echo "here is your password ". $pass;
    }
    ?>


    </Body>
    </HTML>


    that should work. Its uses alot of php and some JS. if you can't see anything for the $_POST then try using var_dump($_POST); cause that will display the ARRAY that it creates.

    Hope that helps.


    Jason

  • #7
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Never Mind. I didnt think It would be that complicated just to pass one var to another page. Is it suppost to be that complicated??? cuz if it is, I really am just going to skip learning PHP.

  • #8
    Registered User
    Join Date
    Feb 2003
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Either your host sucks or your computer sucks, or *cough* *cough* somebody *cough* *cough* sucks.

    Just kiddin

    Try http://www.firepages.com.au and install it on your computer.

    Even a MONKEY can learn PHP.

    HAHAHAHA

    BYE

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    if $_POST['Pass'] does not work (assuming method="post") then try $HTTP_POST_VARS['Pass'];

    if so tell your host to upgrade to PHP >=4.1 ASAP

    if method="get" then use $_GET['Pass'] OR $HTTP_GET_VARS['Pass']

    just to confuse you can also use $_REQUEST['Pass'] , which will pick up any POST , GET or COOKIE vars.



    a foolproof versionof your original code would be...

    Code:
    <html>
    <head>
    <title>HTML Form</Title>
    </Head>
    <Body>
    
    <form action="HandleForm.php" Method=GET>
    Password <input type="TEXT" Name="Pass"><br>
    <input type="SUBMIT" name="SUBMIT">
    </form>
    
    </Body>
    </HTML>
    --------------------------------------------------------------------------------

    HandleForm.php:
    PHP Code:
    <?php
    print "has to work al versions ! >> Your password was ".$HTTP_GET_VARS['Pass']."<br>";

    print 
    "only on PHP>=4.1 ! >> Your password was ".$_GET['Pass']."<br>";

    print 
    "again only on PHP>=4.1 ! >> Your password was ".$_REQUEST['Pass']."<br>";

    print 
    "use braces to stop errors {} Your password was {$_GET['Pass']}<br>";

    ?>
    I know there is a lot of choice there which can be confusing at first - but once you have PHP>=4.1 then you will quickly get used to using $_POST,$_GET,$_COOKIE etc .

    whilst we are here

    $_GET['Pass'];
    and
    $_GET[Pass];
    and
    $_GET['pass'];
    are potentially 3 different variables ! - always quote your variable names unless you intend otherwise & remember variables are case sensitive.

    this does cause problems when utilisising the variables though , eg
    mysql_query("SELECT * FROM $table WHERE field=$_POST['field']");
    will cause an error , using braces however will stop the error.
    mysql_query("SELECT * FROM $table WHERE field={$_POST['field']}");
    Last edited by firepages; 03-11-2003 at 05:05 PM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #10
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Jesh or *cough* *cough* somebody *cough* *cough* sucks.
    [/B]
    lol. I think that would b true. Thanx a BUNCH 4 all the hlp!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    btw, have u noticed that when u highlight the its not a happy face n e more? Its a poor little sad face...


  •  

    Posting Permissions

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