Cetanu Posted September 2, 2009 Share Posted September 2, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172785-file-functions/ Share on other sites More sharing options...
Garethp Posted September 2, 2009 Share Posted September 2, 2009 Well, you should be using a mode for your fopens, look here http://au.php.net/function.fopen Quote Link to comment https://forums.phpfreaks.com/topic/172785-file-functions/#findComment-910754 Share on other sites More sharing options...
Cetanu Posted September 2, 2009 Author Share Posted September 2, 2009 Oh, thanks for enlightening me as to why all of the fopens I saw had "r" It fixed the error, but now it's not writing to my file. Quote Link to comment https://forums.phpfreaks.com/topic/172785-file-functions/#findComment-910917 Share on other sites More sharing options...
wildteen88 Posted September 2, 2009 Share Posted September 2, 2009 Well r stands of read only. For writting use w Take a few minutes and look at the manual for the fopen function, scroll to the modes sub section. It lists all the possible modes and what they each do. Quote Link to comment https://forums.phpfreaks.com/topic/172785-file-functions/#findComment-911110 Share on other sites More sharing options...
Cetanu Posted September 2, 2009 Author Share Posted September 2, 2009 I set it to w+ and it wasn't working... :-\ Quote Link to comment https://forums.phpfreaks.com/topic/172785-file-functions/#findComment-911162 Share on other sites More sharing options...
Cetanu Posted September 3, 2009 Author Share Posted September 3, 2009 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/172785-file-functions/#findComment-911419 Share on other sites More sharing options...
Cetanu Posted September 3, 2009 Author Share Posted September 3, 2009 Can you write $_POST to a txt file? I was wondering if that could be the error. Quote Link to comment https://forums.phpfreaks.com/topic/172785-file-functions/#findComment-911974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.