Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/206779-what-is-wrong-with-my-code/
Share on other sites

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.

<?
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

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

 

<?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

 

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!

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.

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 :P)

 

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?

 

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

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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