-
Can you do this in PHP?
Following is a test piece of PHP code that receives input from an HTML form. In ‘C’ there’s a way to create a container, fill it with data, then write the whole container to disk with one command. You can see that I have used 7 different fwrite commands to accomplish this. Does anyone know how to do something like this in PHP?
I am working toward either a sequential or random access records file. Like it was done in ‘the old days’ before database software was available. We used to use arrays and loops. I am attempting to figure this out using an object.
Any information / input appreciated.
By the way, my code is being interpreted by your web site. 🙁 So, it will not display properly. Any ideas?
Thank you
Scott
serverName = $_POST[‘selectName’] . “\n”;
$rec->userType = $_POST[‘selectType’] . “\n”;
$rec->userChar = $_POST[‘textfieldCharName’] . “\n”;
$rec->userFN = $_POST[‘textfieldFName’] . “\n”;
$rec->userLN = $_POST[‘textfieldLName’] . “\n”;
$rec->userEmail = $_POST[‘textfieldEmail’] . “\n”;
$rec->userComment = $_POST[‘textareaComment’] . “\n”;// Validate email address
if (! ereg(‘[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+’, $textfieldEmail))
{
die(“Please enter a valid email address
“);
}//User must enter an email address
if (strlen($textfieldEmail) == 0 )
{
die(“textfieldEmail is empty
“);
}// Write user file
$userFileName = $textfieldCharName . “.txt”;
$userFileHandle = fopen(“users/” . $userFileName, ‘w’) or die(“can’t open file”);
fwrite($userFileHandle, $rec->serverName);
fwrite($userFileHandle, $rec->userType);
fwrite($userFileHandle, $rec->userChar);
fwrite($userFileHandle, $rec->userFN);
fwrite($userFileHandle, $rec->userLN);
fwrite($userFileHandle, $rec->userEmail);
fwrite($userFileHandle, $rec->userComment);
fclose($userFileHandle);// Success
echo(“Data successfully saved!” . “
“);
// Print received data to screen
echo $rec->serverName . “
“;
echo $rec->userType . “
“;
echo $rec->userChar . “
“;
echo $rec->userFN . “
“;
echo $rec->userLN . “
“;
echo $rec->userEmail . “
“;
echo $rec->userComment . “
“;?>