Page 1 of 1

basic basic question

Posted: Sat Apr 18, 2009 11:16 am
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

Re: basic basic question

Posted: Sat Apr 18, 2009 11:29 am
by jazz090
try:

Code: Select all

echo "welcome to our website ".$firstname." ".$lastname;

Re: basic basic question

Posted: Sat Apr 18, 2009 11:40 am
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?

Re: basic basic question

Posted: Sat Apr 18, 2009 11:53 am
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

Re: basic basic question

Posted: Sat Apr 18, 2009 11:54 am
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?

Re: basic basic question

Posted: Sat Apr 18, 2009 11:56 am
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.

Re: basic basic question

Posted: Sat Apr 18, 2009 11:57 am
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:

Re: basic basic question

Posted: Sat Apr 18, 2009 11:58 am
by jazz090
document.php? i said name it welcome.php or chnage the form target to document.php

Re: basic basic question

Posted: Sat Apr 18, 2009 12:00 pm
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

Re: basic basic question

Posted: Sat Apr 18, 2009 9:17 pm
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.