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 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2006
    Location
    USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get this tutorial example to work for me

    Ok, I've been going through a tutorial so I can eventually learn how to use MySQL and PHP together. I'm doing a very simple thing, but I get the error:
    PHP Notice: Undefined variable: firstname in... on line 15
    It must be something simple I'm doing wrong. Could it have to do with the version of php I'm using? (Which is 4.3.10)

    Here is the tutorial page, I'll mention that I couldn't get any of the examples on this page to work.

    Thanks!

  • #2
    New Coder
    Join Date
    Jan 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would help if you posted your code so far

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's not an error, it's a notice that you're using a variable before it's defined, so you most likely forgot to set it, or typoed when setting it.
    "$question = ( to() ) ? be() : ~be();"

  • #4
    New Coder
    Join Date
    Jan 2006
    Location
    USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No prob, sorry about that. I have tried all three examples, but have commented out others so I'm only trying one at a time.

    HTML Page (mysqlWelcome.html):
    Code:
    <html>
    	<head>
    		<title>mysqlWelcome.html</title>
    	</head>
    
    	<body bgcolor="#ffffff">
    		<p>
    		<!--<A HREF="mysqlWelcomeInc.php?firstname=Kevin&lastname=Yank">Hi, I'm Kevin Yank! </A>
    		-->
    		<FORM ACTION="mysqlWelcomeInc.php" METHOD=GET>
    		First Name: <INPUT TYPE=TEXT NAME="firstname"><BR>
    		Last Name: <INPUT TYPE=TEXT NAME="lastname">
    		<INPUT TYPE=SUBMIT VALUE="GO">
    		</FORM>
    		<!--
    		<FORM ACTION="mysqlWelcomeInc.php" METHOD=GET>
    		First Name: <INPUT TYPE=TEXT NAME="firstname"><BR>
    		Last Name: <INPUT TYPE=TEXT NAME="lastname">
    		<INPUT TYPE=SUBMIT VALUE="GO">
    		</FORM>
    		-->
    		</p>
    	</body>
    
    </html>
    PHP Page(mysqlWelcomeInc.php):
    Code:
    <html>
    	<head>
    		<title>mysqlWelcomeInc.php</title>
    	</head>
    	<body bgcolor="#ffffff">
    		<p>
    		<?php
    			echo( "Welcome to our Web site, $firstname $lastname!" );
    		?>
    		</p>
    	</body>
    </html>

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <html>
        <head>
            <title>mysqlWelcomeInc.php</title>
        </head>
        <body bgcolor="#ffffff">
            <p>
            <?php
                
    echo 'Welcome to our Web site, ' $_GET['firstname'] . ' ' $_GET['lastname'] . '!';
            
    ?>
            </p>
        </body>
    </html>
    "$question = ( to() ) ? be() : ~be();"

  • #6
    New Coder
    Join Date
    Jan 2006
    Location
    USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Velox Letum! Works fine now. Just to ease my sanity, did they leave this out of the tutorial, or was I just supposed to know this? I'm new to php if you couldn't tell; thanks again for the help.
    Kind regards,
    Rob

  • #7
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your tutorial's probably just outdated. Earlier versions of PHP were set up by default so that values from $_GET and $_POST arrays were automatically set up as global vars when a script was called. For security reasons, this doesn't happen by default anymore (though you can still manually set it to do this), and you have to pull your values from these arrays specifically. A lot of tutuorials are still floating around, though, from the old days, and they can be pretty confusing.


  •  

    Posting Permissions

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