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="[email protected]"></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
https://forums.phpfreaks.com/topic/217332-cant-create-a-file-what-is-wrong/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.