Welcome! Log In Create A New Profile

Advanced

eye popping smiley Apply Your Knowledge 3-1 (help please)

Posted by rharris 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
eye popping smiley Apply Your Knowledge 3-1 (help please)
July 31, 2008 03:43PM
eye rolling smiley Good day

I`m building a Guestbook Application my web page is fine but when I enter the first name n last name n comment . The application create a entry but no name appear just this : every entry I enter creates this no error too.

guestbookform[/b]
<?php
$title = "WebBooks.com Guestbook";
include("header.php"winking smiley;
?>
<table border='0' width='600' cellspacing='0' cellpadding='0'>
<tr>
<td><p><b>WebBooks.com Guestbook:</b></p>

<form method='post' action='guestbook.php'>
What is your first name? <input name='firstname' type='text'><br>
What is your last name? <input name='lastname' type='text'><br><br>
What comments do you have about this site?<br>
<textarea name='comments' rows='6' cols='45'>
</textarea><br><br>
<input type='submit'>
</form>

<b>Entries in the Guestbook:</b></br>

<?php
include("./guest.txt"winking smiley;
?>

</td>
</tr>
</table>

<?php
include("footer.php"winking smiley;
?>


Guestbook.php[/b]
<?php
$title = "WebBooks.com Guestbook";
include("header.php"winking smiley;

$fp = fopen("./guest.txt", "a"winking smiley;
fwrite($fp, "<br><b>$firstname $lastname:</b> $comments<br>"winking smiley;
fclose($fp);

echo "Your entry has been added to the guestbook!<br><br>";
echo "<a href='guestbookform.php'>Return to the Guestbook</a>";
?>


Please help !!

Ryan Harris
avatar
Mac
eye popping smiley Re: Apply Your Knowledge 3-1 (help please)
August 01, 2008 06:46AM
$_POST !!!!!!!!!!!!!!!
Anonymous User
eye popping smiley Re: Re: Apply Your Knowledge 3-1 (help please)
August 10, 2008 12:15PM
eye rolling smiley Hi Mac,
I have the same problem like Ryan.
To get to know more about $_POST I studied the whole chapter 5 in the textbook. I tried different places for $_POST.

In guestbookform.php: I placed it in the line after the php script - include guest.txt - like this:
<?php
echo $_POST['firstname'];
echo $_POST['lastname'];
echo $_POST['comments'];
?>

Nothing happened.

Then I placed it in the guestbook.php which I now guess is the right file:
line after fclose($fp);
echo $_POST['firstname'];
echo $_POST['lastname'];
echo $_POST['comments'];

When using your tip regarding debugging error_reporting(E_ALL); in the first line of the php script I got three notices when submitting the query:
Notice: Undefined variable: firstname in C:\xampp\xampp\htdocs\exercises\guestbook.php on line 12

Notice: Undefined variable: lastname in C:\xampp\xampp\htdocs\exercises\guestbook.php on line 12

Notice: Undefined variable: comments in C:\xampp\xampp\htdocs\exercises\guestbook.php on line 12

The rest was ok:
Your entry has been added to the guestbook!

Return to the Guestbook

Please give me a little hint.

Thanks in advance.

Iris
avatar
Mac
eye popping smiley Re: Apply Your Knowledge 3-1 (help please)
August 11, 2008 07:05AM
$_POST can be anywhere as long as it is before the code where you intend to use it. So it must be before
fwrite($fp, "<br><b>$firstname $lastname:</b> $comments<br>"winking smiley;
Anonymous User
eye popping smiley Re: Re: Re: Apply Your Knowledge 3-1 (help please)
August 11, 2008 04:01PM
Thanks Mac but somehow I am really confused now. I cannot solve the problem.
I entered
echo $_POST['firstname'];
echo $_POST['lastname'];
echo $_POST['comments'];
before fwrite...
It does not work.
I checked also the PHP manual for $_POST. I found information but it does not help me.
When I reread page 35 on fwrite I understand that the firstname, the lastname and the comments would be written to the guest.txt file but nothing is in there.
Should I leave out the echo command?
Please give me your support.
Thanks.
Iris confused smiley
avatar
Mac
eye popping smiley Re: Apply Your Knowledge 3-1 (help please)
August 14, 2008 07:13AM
First try to assign $_POST['firstname']; to $firstname
$firstname=$_POST['firstname'];
echo "$firstname";
Anonymous User
eye popping smiley Re: Re: Apply Your Knowledge 3-1 (help please)
August 14, 2008 05:53PM
Oh this is so exciting - also here I found the http://www.tizag.com/phpT/forms.php so helpful. It is highly motivating to see something running smoothly. Here is my script for guestbook.php:
<?php

/**
* @author Iris Philipp
* @copyright 2008
*/
error_reporting(E_ALL);
$title = "WebBooks.com Guestbook";
include("header.php"winking smiley;

$fp = fopen("./guest.txt", "a"winking smiley;

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$comments = $_POST['comments'];

fwrite($fp, "<br><b>$firstname $lastname:<b/> $comments<br>"winking smiley;
fclose($fp);

echo "Your entry has been added to the guestbook!<br><br>";
echo "<a href='guestbookform.php'>Return to the Guestbook</a>";
?>

Iris
Sorry, only registered users may post in this forum.

Click here to login