Hi all, Im kind of newbie to php. Before this script I wrote one, that again stores data in a file, but had 2 parts - one that asks for data and the other displays it+saves it in a file (using $POST).
Now I am writing a script for my website that will ask for name, email and comments. I have planned it to have 3 steps -
ask.php - that asks for the data,
display.php - displays the data and asks for confirmation, and
write.php - actually writes the data to a file, and tells the user his comment has been added.
So, I was told I should use $SESSIONS, since $POST expires after one usage (ex. if I used $POST['name'] in display.php to display the entered name, $POST['name'] wouldn't work for write.php)
This is the code I have now:
ask.php:
<?php
session_start();
$_SESSION['name'] = $_POST['name'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['comment'] = $_POST['comment'];
echo ("That's the comments form");
?>
<form action="/code/comments/display.php" method="post" name="ask">
Name: <input name="name" type="text"><BR>
Email: <input name="email" type="text"><BR>
Comments:<BR><textarea name="comment" cols="40" rows="4" wrap="VIRTUAL"></textarea><BR>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
display.php:
<?php
echo (
"You have submitted the following:
Name: <b> $_SESSION['name'] </b><BR>
Email: <b> $_SESSION['email'] </b><BR>
Comment: <b> $_SESSION['comment'] </b><BR>
");
?>
<form action="/code/comments/write.php" method="post">
<input type="submit" value="Submit">
<input type="button" value="Go Back" onClick="self.history.back();">
</form>
write.php
<?php
//Writing comment to comments.txt file
$fo = fopen("comments.txt", "a");
fwrite($fo,
"$_SESSION['name']\n
$_SESSION['email']\n
$_SESSION['comment']\n");
//fclose($fo)
?>
When I try to access ask.php, I get the following errors:
Warning: session_start(): open(/tmp\sess_1054f78a4d26e6504f94b16712bb6414, O_RDWR) failed: No such file or directory (2) in C:\www\belize\code\comments\ask.php on line 2
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\www\belize\code\comments\ask.php:2) in C:\www\belize\code\comments\ask.php on line 2
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\www\belize\code\comments\ask.php:2) in C:\www\belize\code\comments\ask.php on line 2
Warning: Unknown(): open(/tmp\sess_1054f78a4d26e6504f94b16712bb6414, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
I am running apache 2 under XP, in case that matters.
If you guys give any feedback it would be great, cause I don't wanna leave that as it is, and return to the basic 2-page script with $_POST, you know, advance 🙂
Peace out,
Kaloian