form problem
Posted: Tue Apr 15, 2008 12:39 pm
Hello everyone,
I have this simple form which has three names available to choose from. Depending on which option is chosen, what is submitted gets written to a specific text file. There are 3 text file.
here is what i have. maybe someone could shed some light onto something i am missing.
just to let you know, the permission on the text files are adjusted to 777 and i have tested them separately with a simple script which writes a string of text to each. that's not the problem, i think the problem lies in the structure of the code.
I basically get the die error return 'can't open file'
I have this simple form which has three names available to choose from. Depending on which option is chosen, what is submitted gets written to a specific text file. There are 3 text file.
here is what i have. maybe someone could shed some light onto something i am missing.
just to let you know, the permission on the text files are adjusted to 777 and i have tested them separately with a simple script which writes a string of text to each. that's not the problem, i think the problem lies in the structure of the code.
I basically get the die error return 'can't open file'
Code: Select all
<?php
if ($_POST['message'] != "") {
switch ($_POST['name']) {
case 'Jamil':
$file = 'message.txt';
break;
case 'Razy':
$file = 'message1.txt';
break;
case 'Stephanie':
$file = 'message2.txt';
break;
}
}
?>
<?php
if (!function_exists('file_put_contents')) {
function file_put_contents($file, $contents) {
$fh = fopen($file, 'w') or die("can't open file");
if(!$fh) {
trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
return;
}
fwrite($fh, $contents);
fclose($fh);
}
}
if (file_put_contents($file, htmlspecialchars(stripslashes($_POST['message'])))) {
echo "Your message was recorded";
} else {
echo "An error occurred";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'>
<p class="style2">
<select name="name">
<option>Jamil</option>
<option>Razy</option>
<option>Stephanie</option>
</select>
Message Updater:
</p>
<p class="style2">
<input type="text" name="message" />
</p>
<p class="style2">
<input type="submit" Value="Build"/>
</p>
</form>