Jump to content

PHP multiple forms submission


hakermania

Recommended Posts

I've created this code in PHP and I'm a complete newbie (i've done something in the past regarding email-sending but nothing more...)

So, as I put this code inside my .php file and request it to load, an empty page is presented. What is the actual problem to the code?

Thx in advance for any answer!

 

<?php
$wfilename = $_POST["wfilename"];
$wbody = $_POST["wbody"];
$rfilename = $_POST["rfilename"];
?>
<html>
<head>
<title>Write/Read files!</title>
</head>
<body>
<h1>WRITE FILES</h1>
<form method="post" action="<?php echo $PHP_SELF;?>">
Write filename:<input type="text" size="30" maxlength="30" name="wfilename">:<br />
Body:<br /><textarea rows="20" cols="20" name="wbody" wrap="physical"></textarea><br /> 
<input type="submit" value="write" name="write"><br />
</form><br /> 

<br />
<h1>READ FILES</h1>
<form method="post" action="<?php echo $PHP_SELF;?>">
Write filename:<input type="text" size="30" maxlength="30" name="rfilename"><br />
<input type="submit" value="read" name="read"><br />
</form><br /> 


<?php
if ($_POST['read'])
{
$fh = fopen($rfilename, 'r') or die("");
$theData = fread($fh, 5);
fclose($fh);
echo "$rfilename contains:\n\n$theData";
}
else if ($_POST['write']) {
$fh = fopen($wfilename, 'w') or die("can't open file");
fwrite($fh, $wbody);
fclose($fh);
echo "$wbody was successfully written to $wfilename"
}

Link to comment
Share on other sites

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.