I'm trying to make a comments system to my site, but when i press the post button it gives me errors.
The errors is :
Warning: fopen(comments.txt): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/bikereport/new design v1/Denmark.php on line 11
Warning: fread() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/bikereport/new design v1/Denmark.php on line 12
Warning: fopen(posts.txt): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/bikereport/new design v1/Denmark.php on line 15
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/bikereport/new design v1/Denmark.php on line 17
Warning: fclose() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/bikereport/new design v1/Denmark.php on line 18
Warning: fclose() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/bikereport/new design v1/Denmark.php on line 19
BUT!! I think all the errors are triggered by the first one, the one on line 11
My HTML form :
<form class='' action='' method='POST'>
First and last name:<br>
<input required class='font2 i' style='width: 262px;' type='search' name='name' value=''><br><br>
City or state:
<input required class='font2 i' type='search' name='city' value=''> Phone number:<br>
<input class='font2 i' type='search' name='phone' value=''><br><br>
E-mail:<br>
<input required class='font2 i' type='search' name='email' value=''> Bike serial number:<br>
<input class='font2 i' type='search' name='serial' value=''><br><br>
Information about the bike:<br>
<textarea required class='font2 info' name='info'></textarea><br>
<input type='submit' name='Submit' value='Post'>
</form>
My PHP code
<?php
if($_POST){
$name = $_POST['name'];
$city = $_POST['city'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$serial = $_POST['serial'];
$info = $_POST['info'];
#Get old comments
$old = fopen("posts.txt", "r+t");
$old_comments = fread($old, 1024);
#Delete everything, write down new and old comments
$write = fopen("posts.txt", "w+");
$string = "<div class='font2 post'>".$name."<br><br>".$city."<br>".$phone."
<br>".$email."<br><br>".$serial."<br><br>".$info."<br>\n".$old_comments;
fwrite($write, $string);
fclose($write);
fclose($old);
}
?>