/*
Programmed by Daniel.Schneider@tecfa.unige.ch for educational purposes
This file contains both a submit form and the code to process it.
Have to rewrite this some day ... it was an early days crime - DKS/2007
*/
error_reporting(E_ALL);
// Define the file name
// Important: This file must be writable by the www server
$file_name = "results/result.text";
?>
PHP/Form/File Demo - New Entry
/* **********************************************************************
This section contains the code for processing the form input (see below)
It will only be executed if $insert is not 0 (e.g. if it is set by
the submit button of the form below. Else the if clause is skipped.
*/
if (isset($_POST['insert'])) $insert=$_POST['insert']; else $insert=FALSE;
if ($insert) {
// check existance of file (or try to create it)
$try = is_file($file_name);
if (!$try) {
echo "
Sorry I can't open a file, something is wrong";
exit;
}
// Anti spammer filtering
$login = htmlspecialchars($login);
$password = htmlspecialchars($password);
$fullname = htmlspecialchars($fullname);
$url ="*****";
// this is the stuff we get from the form, we insert it into an array
$input = array ($login, $password, $fullname, $url, $food, $work, $love, $leisure, $sports);
// so we can make a big string with tabs between the elements
// note that we add a \n (line break) to the end of the string.
$output_line = implode ($input, " ")."\n";
// Now open the file (get a file pointer)
// We will append to it and therefore use the "a" option
$output_stream = fopen($file_name, "a");
// and dump the string into the file
$result = fputs ($output_stream, $output_line);
// give feedback
if ($result) {
echo "
Your data have successfully been registered, but we did not use the url (it's sort of thing spammers use).";
}
else {
echo "
Too bad, the file did not want your data.";
}
// close the file pointer
fclose($output_stream);
?>
See all records on file *
Go back to the main page
// EXIT here ... we don't want to see the form again. If you do, kill the exit
exit;
}
?>
/* **********************************************************************
This section will display a html form for input. Parts of the form are
generated by PHP. Not a necessity.
*/
// Generate the various scales ... just to show off some php
// Change the list of scales below, elements need to be SIMPLE strings
$scales = array("food", "work", "love", "leisure", "sports");
function scale ($thing) {
echo "
Importance of $thing:
";
echo "
";
echo "
";
}
/* the stuff below could have been done with a for loop,
but I was exploring a bit :) */
function dump_scales () {
global $scales;
reset($scales);
do {
$scale = scale(current($scales));
echo "$scale\n";
}
while (next($scales));
}
?>
Please fill in all the following fields. Lies are an option ;)
See all records on file *
Go back to the main pageD.K.S.