Jump to content

File Functions


Cetanu

Recommended Posts

I want to have it so that members can ask for help by submitting a query and having their posted values inserted into a file. It won't work, when I click Contact it says this:

 

ERROR

 

The requested URL could not be retrieved

 

While trying to retrieve the URL: http://d9fans.freezoka.com/contact.php

 

The following error was encountered:

 

Zero Sized Reply

Squid did not receive any data for this request.

 

Your cache administrator is webmaster.

 

Code:

<?php 
if(!isset($_POST['submit'])){
echo "
<h2>Contact the Admin</h2>
<form action='contact.php' method='post'>
Name: <input type='text' maxlength='20' name='name'/><br/>
Email: <input type='text' name='email'/><br/>
Subject: <input type='text' maxlength='50' name='subj'/><br/>
Body: <br/>
<textarea cols='50' rows='5' name='body'></textarea><br/>
Date: <input type='text' value='".date("D, M d, Y")."' readonly='readonly' name='date'/><br/>
<input type='submit' name='submit' value='Contact'/> | <input type='reset' value='Clear'/>
</form>";
} 
else{ 
if(!$_POST['name'] || !$_POST['email'] || !$_POST['subj'] || !$_POST['body'] || !$_POST['date']){
echo "<strong>Fill in all required fields. <a href='contact.php' title='Back'>Try again.</a></strong>"; 
} 
$contactfile = fopen("contact.txt"); 
fwrite($contactfile , "Name: ".$_POST['name']."<br/>
Email: ".$_POST['email']."<br/>
Subject: ".$_POST['subj']."<br/> 
Body: ".$_POST['body']."<br/> 
Date: ".$_POST['date']."<br/><br/><br/>"); 
fclose($contactfile); 
echo "<script>alert('Successful.'); location='contact.php';</script>"; 
}   

$filec = fopen("contact.txt"); 
while(!feof($filec)){ 
    echo fgets($filec); 
    } 
fclose($filec); 
?>

Link to comment
https://forums.phpfreaks.com/topic/172785-file-functions/
Share on other sites

The new code that won't write to my file is....:

 

<?php 
if(!isset($_POST['submit'])){
echo "
<h2>Contact the Admin</h2>
<form action='contact.php' method='post'>
Name: <input type='text' maxlength='20' name='name'/><br/>
Email: <input type='text' name='email'/><br/>
Subject: <input type='text' maxlength='50' name='subj'/><br/>
Body: <br/>
<textarea cols='50' rows='5' name='body'></textarea><br/>
Date: <input type='text' value='".date("D, M d, Y")."' readonly='readonly' name='date'/><br/>
<input type='submit' name='submit' value='Contact'/> | <input type='reset' value='Clear'/>
</form>";
} 
else{ 
if(!$_POST['name'] || !$_POST['email'] || !$_POST['subj'] || !$_POST['body'] || !$_POST['date']){
echo "<strong>Fill in all required fields. <a href='contact.php' title='Back'>Try again.</a></strong>"; 
} 
$contactfile = fopen("contact.txt" , "w+"); 
fwrite($contactfile , "Name: ".$_POST['name']."<br/>
Email: ".$_POST['email']."<br/>
Subject: ".$_POST['subj']."<br/> 
Body: ".$_POST['body']."<br/> 
Date: ".$_POST['date']."<br/><br/><br/>"); 
fclose($contactfile); 
echo "<script>alert('Successful.'); location='contact.php';</script>"; 
}   

$filec = fopen("contact.txt" , "w+"); 
while(!feof($filec)){ 
    echo fgets($filec); 
    } 
fclose($filec); 

echo "</p>";
?>

Link to comment
https://forums.phpfreaks.com/topic/172785-file-functions/#findComment-911419
Share on other sites

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.