-
If statement help:
PHP Code:
<?php
[B]If(($_POST['R\W']) == 'r'){[/B]
$contents = @fopen($_POST['file'], "r") or die("Error opening1");
$reading = fread($contents, filesize($_POST['file'])) or die("Error Reading");
@fclose($_POST['file']);
echo $_POST['file'],"/n",$reading;
} Else {
$contents = @fopen($_POST['file'], "w") or die("Error opening2");
@fwrite($contents,"New file created") or die("Error writing");
@fclose($_POST['file']);
}
?>
How do i check posts value? seems im doing it wrong-it always goes to elses, even if $_POST['R\W'] does equal r
thanks :wave:
-
Re: If statement help:
Have you tried checkign the variable contains what you expect it to contain? Try this at the beginningof your script, does it output what you expect?
PHP Code:
echo($_POST['R\W']);
-
Re: If statement help:
thanks visualad, i didnt know php was case sensitive (r\w) was what it was.
Can you please explain how id add a new line to an echo?
-
Re: If statement help:
You need to use a string in double qutoes. For a widnows newline you need a carridge return and line feed, for unix yujust need a line feed:
Code:
echo("\r\n"); //windows
echo("\n"); // unix
-
Re: If statement help:
thanks visual, but it still isnt working :confused: :confused:
Ive tried it these ways:
PHP Code:
echo ($_POST['R/W']);
echo("\r\n");
PHP Code:
echo ($_POST['R/W']),echo("\r\n");
and both times the page looks like this:
r visitorcount.txt 916
instead of
r
visitorcount.txt
916
any clues?
-
Re: If statement help:
Do you mean in the HTML? If so then you need to use "<br />" which created a line break.
-
Re: If statement help:
when i am echo'ing a variable to find the value or check the value, i usually write it to a test file, like so:
PHP Code:
$handle = fopen($filename, 'a'));
fwrite($handle, "$_POST['R/W']");
fclose($handle);
the reason i usually use a file rather than echoing the variable is because a file is more reliable to get the info out of.
-
Re: If statement help:
does a mean for append? i think it does? so theres an r,w,a?
and also, i mean that i when you echo at two different spots, they appear on one line, i hope the < br /> does it
-
Re: If statement help:
no, "a" is for "wrighting only, if the file does not exist, attempt to create it"
look here for all the file handles:
http://us4.php.net/manual/en/function.fopen.php