basic basic question
Moderator: General Moderators
basic basic question
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
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
try:
Code: Select all
echo "welcome to our website ".$firstname." ".$lastname;Re: basic basic question
(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?
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
make a single php file named: welcome.php and put this innit:
run the code and submit and it should work
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> </div>
<div>Lastname: <input type="text" name="lastname" size="30" /></div>
<div> </div>
<div><input type="submit" value="Submit" /></div>
</form>
<div> </div>
<div>
<?php
echo "firstname: ".$firstname;
echo "<br />";
echo "lastname: ".$lastname;
?>
</div>
</body>
</html>
Last edited by jazz090 on Sat Apr 18, 2009 11:57 am, edited 3 times in total.
Re: basic basic question
I really am new at this - what do you mean please?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?
Re: basic basic question
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
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:
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
document.php? i said name it welcome.php or chnage the form target to document.php
Re: basic basic question
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
Forget all of the suggestions made up to this point. None of them* address your problem because of this:
Download and install XAMPP
*tasairis was on the right track.
Edit: This post was recovered from search engine cache.
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.AVB99 wrote:C:\Users\Aidan\Documents\chapter 3\document.php
Download and install XAMPP
*tasairis was on the right track.
Edit: This post was recovered from search engine cache.