basic basic question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AVB99
Forum Newbie
Posts: 3
Joined: Sat Apr 18, 2009 11:07 am

basic basic question

Post by AVB99 »

I'm trying to learn php and am using a book by Kevin yank - I've fallen at teh first fence because the examples given do not work. Can anyone please advise as to what is going wrong?

I'm told to make two files

welcome4.html contains the following code

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>First name</title>
</head>

<body>
<form action="welcome4.php" method="post">
<label>First name: <input type="text" name="fisrtname" />
</label><br />
<label>last name: <input type="text" name="lastname" />
</label><br />
<input type="submit" value="GO" />
</form>
</body>

</html>


Welcome4.php contains the following code:

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
<?php
$firstname = $_POST[ 'firstname' ];
$lastname = $_POST[ 'lastname' ];
echo "Welcome to our website, $firstname $lastname";
?>

</body>

</html>

Welcome1.html seems to work as a form and I can submit the data.

Welcome4.php simply displays the entire code from that page. I'm stumped. Can anyone please advise? Thank you. Aidan
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: basic basic question

Post by jazz090 »

try:

Code: Select all

echo "welcome to our website ".$firstname." ".$lastname;
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: basic basic question

Post by requinix »

(Won't make a difference.)

AVB99: Fill out the form then look at the HTML source of the welcome4.php result. Do you see any <?php tags?
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: basic basic question

Post by jazz090 »

make a single php file named: welcome.php and put this innit:

Code: Select all

<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
?>
<!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" />
</head>
 
<body>
<form action="welcome.php" method="post">
<div>Firstname: <input type="text" name="firstname" size="30" /></div>
<div>&nbsp;</div>
<div>Lastname: <input type="text" name="lastname" size="30" /></div>
<div>&nbsp;</div>
<div><input type="submit" value="Submit" /></div>
</form>
<div>&nbsp;</div>
<div>
<?php
echo "firstname: ".$firstname;
echo "<br />";
echo "lastname: ".$lastname;
?>
</div>
</body>
</html>
run the code and submit and it should work
Last edited by jazz090 on Sat Apr 18, 2009 11:57 am, edited 3 times in total.
AVB99
Forum Newbie
Posts: 3
Joined: Sat Apr 18, 2009 11:07 am

Re: basic basic question

Post by AVB99 »

tasairis wrote:(Won't make a difference.)

AVB99: Fill out the form then look at the HTML source of the welcome4.php result. Do you see any <?php tags?
I really am new at this - what do you mean please?
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: basic basic question

Post by jazz090 »

cant put it any simpler than that, make a new file in notepad or dreamweaver whatever u use, copy and paste whatever i have put above and paste it into the document, dun the code and submit both names and the script will work.
AVB99
Forum Newbie
Posts: 3
Joined: Sat Apr 18, 2009 11:07 am

Re: basic basic question

Post by AVB99 »

in response to jazz09 this was the result:

Notice: Undefined index: firstname in C:\Users\Aidan\Documents\chapter 3\document.php on line 2

Notice: Undefined index: lastname in C:\Users\Aidan\Documents\chapter 3\document.php on line 3

Firstname:

Lastname:




Notice: Undefined index: firstname in C:\Users\Aidan\Documents\chapter 3\document.php on line 23
firstname:

Notice: Undefined index: lastname in C:\Users\Aidan\Documents\chapter 3\document.php on line 25
lastname:
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: basic basic question

Post by jazz090 »

document.php? i said name it welcome.php or chnage the form target to document.php
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: basic basic question

Post by jazz090 »

and the vars are undefined cos u didnt copy and past properly, there is a php code beginig of the file and u negated that
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: basic basic question

Post by McInfo »

Forget all of the suggestions made up to this point. None of them* address your problem because of this:
AVB99 wrote:C:\Users\Aidan\Documents\chapter 3\document.php
PHP requires a server to parse PHP documents. Without the server, your documents are just text files. Your HTML file works because HTML files do not require a server.

Download and install XAMPP

*tasairis was on the right track.

Edit: This post was recovered from search engine cache.
Post Reply