starvator Posted July 5, 2010 Share Posted July 5, 2010 My submission form: <form name="verification" action="verification1.php" method="post"> Code 1: <input type="text" name="code1" /><br> Code 2: <input type="text" name="code2" /><br> <input type="checkbox" name="agree" value="yes" /> I agree to the terms<br> <input type="submit" value="Submit" /> verification1.php: <? if($_POST['code1'] == "chicken" && $_POST['code2'] == "dog") $content = $session->login($_POST['user']; $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($file, $content); fclose($file); ?> What I am trying to do is make a submission form where the person has to enter chicken in box one and dog in box 2. If not, then the form will not submit their username to the text file. Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/ Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 Are you getting any error messages? What do you expect to happen? What is happening? Ken Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081355 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 Are you getting any error messages? What do you expect to happen? What is happening? Ken I am getting the error Parse error: syntax error, unexpected ';' in /home/a3232513/public_html/verification1.php on line 3 I am expecting for it to work properly, i want to be able to have the username only submitted if the codes are right. Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081357 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 Where is "$session" being defined? Ken Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081361 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 <? if($_POST['code1'] == "chicken" && $_POST['code2'] == "dog") $content = $session->username; $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($file, $content); fclose($file); ?> This no longer gives me the same error, and i think i fixed the content part, but it now it gives me: Warning: fopen(textfile.txt) [function.fopen]: failed to open stream: Permission denied in /home/a3232513/public_html/verification1.php on line 5 PHP Error Message Warning: fclose(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081362 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 Where is "$session" being defined? Ken <? if($_POST['code1'] == "chicken" && $_POST['code2'] == "dog") $content = $session->username; $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($file, $content); fclose($file); ?> This no longer gives me the same error, and i think i fixed the content part, but it now it gives me: Warning: fopen(textfile.txt) [function.fopen]: failed to open stream: Permission denied in /home/a3232513/public_html/verification1.php on line 5 PHP Error Message Warning: fclose(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081364 Share on other sites More sharing options...
MatthewJ Posted July 5, 2010 Share Posted July 5, 2010 <?php if($_POST['code1'] == "chicken" && $_POST['code2'] == "dog") { $content = $session->login($_POST['user']); $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($file, $content); fclose($file); } ?> how about that? Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081368 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 <?php if($_POST['code1'] == "chicken" && $_POST['code2'] == "dog") { $content = $session->login($_POST['user']); $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($file, $content); fclose($file); } ?> how about that? IT works better but now i get this error: Warning: fclose(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081369 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 NOw I have this: <? include("include/session.php"); ?> <form name="verification" action="verification1.php" method="post"> Code 1: <input type="text" name="code1" /><br> Code 2: <input type="text" name="code2" /><br> <input type="checkbox" name="agree" value="yes" /> I agree to the terms<br> <input type="submit" value="Submit" /> And THis: <?php include("include/session.php"); if($_POST['code1'] == "chicken" && $_POST['code2'] == "dog") { $content = $session->username; $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($file, $content); fclose($file); } ?> ANd get thiss error: PHP Error Message Warning: fopen(textfile.txt) [function.fopen]: failed to open stream: Permission denied in /home/a3232513/public_html/verification1.php on line 6 Free Web Hosting PHP Error Message Warning: fwrite(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 7 Free Web Hosting PHP Error Message Warning: fclose(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 8 PLEASE HELP! Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081374 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 The first parameter in the fwrite and fclose functions is a file pointer, not a file name, use <?php $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($Saved_File, $content); fclose($Saved_File); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081376 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 The first parameter in the fwrite and fclose functions is a file pointer, not a file name, use <?php $file = "textfile.txt"; $Saved_File = fopen($file, 'w'); fwrite($Saved_File, $content); fclose($Saved_File); ?> Ken I did this but i still get: Warning: fopen(textfile.txt) [function.fopen]: failed to open stream: Permission denied in /home/a3232513/public_html/verification1.php on line 6 Free Web Hosting PHP Error Message Warning: fwrite(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 7 Free Web Hosting PHP Error Message Warning: fclose(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 8 Free Web Hosting Does the first error mean i need to change the file permissions? Necause I want the text file to be "secure" if you know what i mean. I do not want people to be able to view it. Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081382 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 The first error says "Permission denied" which means the process running the script does not have permission the write the file where you want to put it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081384 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 The first error says "Permission denied" which means the process running the script does not have permission the write the file where you want to put it. Ken Ok, so i changed a few things ( I got someone to help me ) form: <form name="verification" action="verification1.php" method="post"> Code 1: <input type="text" name="code1" /><br> Code 2: <input type="text" name="code2" /><br> <input type="checkbox" name="agree" value="yes" /> I agree to the terms<br> <input type="submit" value="Submit" /> verification1: <?php // Include Session Object (Which includes Other Files and Initializes all objects) include('include/session.php'); // Get the user information from Database $userinfo = $database->getUserInfo($session->username); // Store results If Correct: if($_POST['code1'] != "chicken"){ exit('Code 1 Mismatch<br />'); } if($_POST['code2'] != "dog"){ exit('Code 2 Mismatch<br />'); } if(!isset($_POST['agree'])){ exit('You did not agree to the Terms & Conditions'); // If you get this even if you click, change != "yes" to != "checked" } $filename = "textfile.txt"; $f = fopen($file, 'a+'); # Check: http://php.net/fopen fwrite($f, "\n",$email); # Add email to file (On a new line) fclose($f); # Close file. echo('Success!'); ?> I now get these errors : PHP Error Message Warning: fopen() [function.fopen]: Filename cannot be empty in /home/a3232513/public_html/verification1.php on line 22 Free Web Hosting PHP Error Message Warning: fclose(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 26 Free Web Hosting Success! Do you understand what these ones mean? Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081386 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 fopen needs a filename for the first parameter, you've given it an undefined variable. The error messages that are displayed usually tell you whats wrong. Use <?php $filename = "textfile.txt"; $f = fopen($filename, 'a+'); # Check: http://php.net/fopen ?>p You had this correct in the earlier code. Why did you change it? Ken Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081392 Share on other sites More sharing options...
starvator Posted July 5, 2010 Author Share Posted July 5, 2010 fopen needs a filename for the first parameter, you've given it an undefined variable. The error messages that are displayed usually tell you whats wrong. Use <?php $filename = "textfile.txt"; $f = fopen($filename, 'a+'); # Check: http://php.net/fopen ?>p You had this correct in the earlier code. Why did you change it? Ken thats a typo i fixed it but i still get these errors: PHP Error Message Warning: fopen(textfile.txt) [function.fopen]: failed to open stream: Permission denied in /home/a3232513/public_html/verification1.php on line 22 Free Web Hosting PHP Error Message Warning: fclose(): supplied argument is not a valid stream resource in /home/a3232513/public_html/verification1.php on line 24 Free Web Hosting Success! I know i need to change the file permission but how can i do that and make it not writable or readable by everyone on the planet? I want to make it secure... Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081402 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 Put the file outside the webroot and give it the appropriate permissions. That way your script can get to it, but no one else can via the web. Or use a database to record everything. Much more secure. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081442 Share on other sites More sharing options...
jcbones Posted July 5, 2010 Share Posted July 5, 2010 Try changing the file permission to 0600 This give the file owner read and write, and everyone else nothing. Quote Link to comment https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/#findComment-1081450 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.