coding php for class

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
emetrack123
Forum Newbie
Posts: 4
Joined: Thu Mar 06, 2014 7:10 am

coding php for class

Post by emetrack123 »

ok here is my problem
we are making a sign up form for a guest book well here is the break down
Signup Forum Guestbook
Name added (shows the current user that just signed up)

Code: Select all

<?php
		$name = ($_POST['name']);
		$email = ($_POST['email']);
		$guestbook = fopen("guestbook.txt", "ab");
		if (is_writeable("guestbook.txt")) {
			if (fwrite($guestbook, $name.", ".$email . "\n"))
				echo 
				"<h1>Name Added</h1><br />",
"<p><strong>Name</strong>:", $name, "<br /><strong>E-mail</strong>:", $email, "</p></form><br />";

			else
				echo "<p>Cannot add your name to the guest book.</p>\n";
		}
		else 
			echo"<p> cannot write to the file.</p>\n";
			fclose($guestbook);
	
?>
View Guest book

Code: Select all

<?php
echo "<h1>Visitors</h1><br />";
$viewgb = file("guestbook.txt");

for ($i=0; $i<count($viewgb); ++$i) {
	$visitors =  explode(", ", $viewgb[$i]);
	sort($visitors);
	echo ($i+1)," <strong>Name:</strong>", $visitors[0], "<br />";
	echo "<strong>Email:</strong>",$visitors[1],"<br />";
	echo "<hr />";
	}
?>
now here is my problem in the view guest book i have to make a link that sorts the guestbook in ascending order and descending and then have a button that you can enter the row you want to delete and then press the delete button and it goes back to the list but deletes it

well here is the teachers sample
http://www.eiu-mis.net/samples/proj3/GuestBook.html

and here is mine
http://4530ceevulukwu.eiu-mis.net/Project3.php

it would be better if you go through the sample and mine to see what i am doing wrong
PhpExile
Forum Newbie
Posts: 17
Joined: Wed Mar 05, 2014 12:45 pm

Re: coding php for class

Post by PhpExile »

are you getting the contents of the file and putting it into an array? sort is ASC and rsort is DESC order. Is a database completely out of the question? You will save yourself alot of headaches using a database to store the entries then it would be so much easier to delete any row you want. MySQL would be a good thing to learn and its easy :)
Post Reply