PDA

Click to See Complete Forum and Search --> : If statement help:


|2eM!x
Jul 1st, 2005, 12:30 AM
<?php
If(($_POST['R\W']) == 'r'){
$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:

visualAd
Jul 1st, 2005, 01:28 AM
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?

echo($_POST['R\W']);

|2eM!x
Jul 1st, 2005, 01:57 AM
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?

visualAd
Jul 1st, 2005, 02:10 AM
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:

echo("\r\n"); //windows
echo("\n"); // unix

|2eM!x
Jul 1st, 2005, 02:27 AM
thanks visual, but it still isnt working :confused: :confused:

Ive tried it these ways:

echo ($_POST['R/W']);
echo("\r\n");

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?

visualAd
Jul 1st, 2005, 02:47 AM
Do you mean in the HTML? If so then you need to use "<br />" which created a line break.

ALL
Jul 1st, 2005, 04:37 PM
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:
$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.

|2eM!x
Jul 2nd, 2005, 01:53 AM
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

ALL
Jul 2nd, 2005, 03:55 PM
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