Hi!
I am a beginner with PHP and MySQL. I have 3 months to create a website and am starting now!
I have a bit of html experience and am now branching to the server side.
I have begun the tutorial below and have hit a road block.
MySQL :: Building a Database-Driven Web Site Using PHP and MySQL
Can someone please fill me in as to why I continue to get
"Notice: Undefined variable: firstname in C:\xampp\htdocs\Mysite\php.php on line 9
Notice: Undefined variable: lastname in C:\xampp\htdocs\Mysite\php.php on line 9
Welcome to our Web site, ! "
My html code
<title>Untitled Document</title>
</head>
<body>
<FORM ACTION=“php.php” METHOD=GET>
First Name: <INPUT TYPE=TEXT NAME=“firstname”><BR>
Last Name: <INPUT TYPE=TEXT NAME=“lastname”>
<INPUT TYPE=SUBMIT VALUE=“GO”>
</FORM>
</body>
</html>
My php code
<HTML>
<HEAD>
<TITLE>Today’s Date</TITLE>
</HEAD>
<BODY>
<?php
echo( “Welcome to our Web site,
$firstname $lastname!” );
?>
</BODY>
</HTML>
Thank you for the help. If you have any posting tips please let me know and I will be sure to comply.
butblack
you are not reading the form values in the php page…
i.e you can read it by using $_GET(), because you used get method as your form method…
like this you can read the form data in php page;
$firstname=$_GET[‘firstname’];
$lastname= $_GET[‘lastname’];
echo “Welcome to our Web site, $firstname $lastname!”;
Let me fix that for you
$_GET is an array (okay, a superglobal array), not a function 
Here’s what I do:
<?php
echo "Welcome to our Web site";
// check and display parameter otherwise display message
$firstname = isset($_GET[''firstname]) ? $_GET[''firstname]) : 'Missing firstname';
$lastname = isset($_GET[''lastname]) ? $_GET[''lastname]) : ' Missing lastname';
echo $firstname, ' ', $lastname!;
?>
Hey, thanks so much for the help! I tried and it’s still not working. I’m now getting a syntax error in Dreamweaver. Maybe that is what the issue is? I’m using Dreamweaver cs5.
New code is:
html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<FORM ACTION="php.php" METHOD=GET>
First Name: <INPUT TYPE=TEXT NAME="firstname"><BR>
Last Name: <INPUT TYPE=TEXT NAME="lastname">
<INPUT TYPE=SUBMIT VALUE="GO">
</FORM>
</body>
</html>
php
<HTML>
<HEAD>
<TITLE>Today's Date</TITLE>
</HEAD>
<BODY>
<?php
echo( "Welcome to our Web site,
$firstname $lastname!" );
?>
</BODY>
</HTML>
your method and types need quotes around them.
you arnt setting $firstname or $lastname anywhere on the page.
The example you’re following seems to be relying on register_globals being true; this has been deprecated since PHP 5.3
Try this…
<?php
$forename = filter_var('fname', INPUT_GET, FILTER_SANITIZE_SPECIAL_CHAR);
$surname = filter_var('sname', INPUT_GET, FILTER_SANITIZE_SPECIAL_CHAR);
?>
<html>
<head>
<title>Demo</title>
</head>
<body>
<form action="#" method="get">
Forename: <input type="text" name="fname" />
Surname: <input type="text" name="sname" />
<input type="submit" value="submit" />
</form>
<?php if($forename && $surname): ?>
<p>
Hello <?php echo $forename, ' ', $surname; ?>
</p>
<?php endif; ?>
</body>
</html>
Did you see the post made by John Betong ? It should solve your issue too. 
AnthonySterling - Did you see the post made by John Betong ? It should solve your issue too.
I’m still getting errors. It’s bizarre! So where I’m at right now, I have the html file called html.html and a php file called php.php. I am trying to use the embedded link and var to welcome a user.
I tried both John Betong and AnthonySterling’s code (found below) and get the error:
Notice: Use of undefined constant FILTER_SANITIZE_SPECIAL_CHAR - assumed ‘FILTER_SANITIZE_SPECIAL_CHAR’ in C:\xampp\htdocs\Mysite\php.php on line 8
Notice: Use of undefined constant FILTER_SANITIZE_SPECIAL_CHAR - assumed ‘FILTER_SANITIZE_SPECIAL_CHAR’ in C:\xampp\htdocs\Mysite\php.php on line 9
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<FORM ACTION="php.php" METHOD=GET>
First Name: <INPUT TYPE=TEXT NAME="firstname"><BR>
Last Name: <INPUT TYPE=TEXT NAME="lastname">
<INPUT TYPE=SUBMIT VALUE="GO">
</FORM>
</body>
</html>
<HTML>
<HEAD>
<TITLE>Today's Date</TITLE>
</HEAD>
<BODY>
<?php
$forename = filter_var('fname', INPUT_GET, FILTER_SANITIZE_SPECIAL_CHAR);
$surname = filter_var('sname', INPUT_GET, FILTER_SANITIZE_SPECIAL_CHAR);
?>
<html>
<head>
<title>Demo</title>
</head>
<body>
<form action="#" method="get">
Forename: <input type="text" name="fname" />
Surname: <input type="text" name="sname" />
<input type="submit" value="submit" />
</form>
<?php if($forename && $surname): ?>
<p>
Hello <?php echo $forename, ' ', $surname; ?>
</p>
<?php endif; ?>
</body>
</html>
Sorry, I made a typo.
<?php
$forename = filter_var('fname', INPUT_GET, FILTER_SANITIZE_SPECIAL_CHARS);
$surname = filter_var('sname', INPUT_GET, FILTER_SANITIZE_SPECIAL_CHARS);
?>
<html>
<head>
<title>Demo</title>
</head>
<body>
<form action="#" method="get">
Forename: <input type="text" name="fname" />
Surname: <input type="text" name="sname" />
<input type="submit" value="submit" />
</form>
<?php if($forename && $surname): ?>
<p>
Hello <?php echo $forename, ' ', $surname; ?>
</p>
<?php endif; ?>
</body>
</html>
Ok so no errors!
Still, I go from my Php website, and that brings me to to the site but does not show any Hello $forename or $surename.
So the form works but it ends there. It doesn’t move from the html to the php. The code was pure php. Your thoughts?
Thanks for the help so far, really appreciate it!
Yeah! What happens is the form goes blank and the top url changes
With entries on the html page of name: forename last name: surname
the url becomes
http://localhost/Mysite/php.php?firstname=forename&lastname=surename
then in the php form typing
forename1 and surname1
the url becomes
http://localhost/Mysite/php.php?fname=forename1&sname=surname1#
There is no Hello and name appears.
Well, this is embarrassing!
Give this a go, I’ve actually tested this one. 
<?php
$fname = filter_input(INPUT_GET, 'fname', FILTER_SANITIZE_SPECIAL_CHARS);
$sname = filter_input(INPUT_GET, 'sname', FILTER_SANITIZE_SPECIAL_CHARS);
?>
<html>
<head>
<title>Demo</title>
</head>
<body>
<form action="#" method="get">
Forename: <input type="text" name="fname" />
Surname: <input type="text" name="sname" />
<input type="submit" value="submit" />
</form>
<?php if($fname && $sname): ?>
<p>
Hello <?php echo $fname, ' ', $sname; ?>
</p>
<?php endif; ?>
</body>
</html>
Great! Thank you. Quick question. When I type my info in the first HTML why doesn’t it just appear. I guess what I’m asking is why is there a php form two times?
Because you need to submit the data to the server, the server then generates the HTML output with the data you submitted in the form.
There are ways to avoid this, but let’s learn the basics first. 
OK sounds good. I ran through the tutorials. I’m putting all of my time into this endeavor. Any suggestions of tutorials or books to follow?