
Originally Posted by
recore684
The functions I am using for my guestbook are not working properly
Yet you fail to:
- describe what "working properly" means. Code always does what it's supposed to, but not necessarily what you want it to.
- indicate which function is causing problems.
- show an example of usage.
- provide any error messages, or even state if there were any error messages.
You wouldn't go to a doctor and just say, "Something's wrong." You'd provide information to help with the diagnosis. The same is true when reporting software bugs, and asking for help with problematic code.
A final note before continuing: when posting code, please use the [php]...[/php], [html]...[/html], or [code]...[/code] pseudo-tags and use spaces, not tabs, to indent.
@$mf = fopen("../guestbook/guestbook.txt", "r");
This is perhaps a style issue more than anything else, but it seems to be traditional to place the error suppression operator on the right-hand side of assignment expressions:
PHP Code:
$mf = @fopen('../guestbook/guestbook.txt', 'r');
while (!feof($mf))
{
  $entry = fgets($mf, 3000);
  if (!feof($mf))
Again, not errors, but two things to consider.
Do you actually check for input longer than 3000 characters when updating the guestbook? You don't appear to, and this could break your file format.
You don't need to check for EOF a second time. The fgets function will return false if it encounters EOF immediately, so
is sufficient.
$data = explode("\t", $entry);
$out .= "<blockquote> [...]";
This is bad form (but not an error in PHP 5, at least) because you haven't defined out. You do this in the valid function, too.
$out .= "<cite> [...] <br /";
You haven't included a closing angle bracket.
function insertData($outstring, $guestbook)
{
  @$mf = fopen($gbFile, "a");
The variable, gbFile, isn't defined. Again, this isn't an error, but it's still wrong.
function processData($fname, $lname, $gender, $comment)
{
  $outstring = date('h:i a') . "\t" . date('j F, Y') . "\t";
Most operations on dates should be using exactly the same time stamp. Call time, store its value, then pass it to the two date calls.
function valid($fname, $lname, $gender, $comment)
{
  if (is_null($fname) || empty($fname) || $fname == "")
You can probably replace all of that with:
PHP Code:
if(empty($fname)) {
Read the PHP documentation for the empty function.
If none of that helps, then you need to provide more information.
Mike
Bookmarks