Jump to content

Cant create a file? What is wrong?


tempguy

Recommended Posts

This should create a gb.txt in the local folder but its not creating it? What is wrong with it pls help  :confused:

 

<html>

<head>
<title>Guestbook</title>
</head>
<body>

<?php
extract($_REQUEST);
?>

<?php

if(isset($submit))
{
    saveGuestbook($name, $email, $comments);
    showGuestbook();
    }
elseif($check){
showGuestbook();
}else{
callForm();
}
?>

<?php
function showGuestbook()
{
echo "<body bgcolor='#DAE5CD'>";
echo "<font color='#cc3333' size='+2'><b>Thank You!</b></font> <br><br>";
$data = file("gb.txt");
foreach ($data as $line)
    {
    $line = rtrim($line);
    echo "<hr>";
    list($name, $email, $comments) = split ("\t", $line);
    echo "Name: $name<br>";
    echo "Email: $email<br>";
    echo "Comments: $comments<br>";
    }
    echo "<hr><p><a href = 'guestbook.php'>Click here </a> to go back </p>";
}

function saveGuestbook($nam, $mal, $com)
{
$fh = fopen("gb.txt");
$nameData = $nam. "\t";
fputs($fh, $nameData);
$mailData = $mal. "\t";
fputs($fh, $mailData);
$commnetsData = $com. "\n";
fputs($fh, $commnetsData);
fclose($fh);
}

function callForm()
{
print <<<DONE
<font color="#CC0000" size="+2">Please sign our guestbook</font> <br > <br >
<form name="Guestbook" method="post">
<table bgcolor="#DAE5CD">
  <tr>
    <td valign="top">Name: </td>
    <td><input type="text" name="name" size="25" value="Your Name"></td>
  </tr>
  <tr>
    <td valign="top">E-mail:</td>
    <td><input type="text" name="email" size="25" value="example@mail.com"></td>
  </tr>
  <tr>
    <td valign="top">Comments:</td>
    <td><textarea rows="5" cols="30" name="comments">Comments</textarea></td>
     </tr>
  <tr>
    <td></td>
       <td align="right"><input type="submit" name="submit" value="submit">  
      <input type="reset" value="Clear"> </td>
  </tr>
</table>
</form>

<p>Want to check out our <a href="guestbook.php?check=check"> guestbook?</a></p>
DONE;
}
?>
</body>
</html>

Link to comment
Share on other sites

Your fopen() statement is missing the second parameter.

 

You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php errors in your code will be reported and displayed. You will save a ton of time.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.