...

View Full Version : Can't get this tutorial example to work for me



robdog119
02-14-2006, 07:12 PM
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 (http://dev.mysql.com/tech-resources/articles/ddws/17.html), I'll mention that I couldn't get any of the examples on this page to work.

Thanks!

Zegg90
02-14-2006, 07:59 PM
It would help if you posted your code so far :)

Velox Letum
02-14-2006, 09:22 PM
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.

robdog119
02-14-2006, 09:25 PM
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):

<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):

<html>
<head>
<title>mysqlWelcomeInc.php</title>
</head>
<body bgcolor="#ffffff">
<p>
<?php
echo( "Welcome to our Web site, $firstname $lastname!" );
?>
</p>
</body>
</html>

Velox Letum
02-14-2006, 09:32 PM
<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>

robdog119
02-14-2006, 09:55 PM
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. :thumbsup:
Kind regards,
Rob

Kid Charming
02-14-2006, 10:17 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum