This is 2 different pages of code:
The first part is a form that has input for first/last name, and then email…
The second part is supposed to store the input and show the user signed into a “guest book” which is stored as a text file.
The webpage displays the form properly but after i submit it, it just has a blank screen. I did not do this code it was made by someone on the forum to help me. Any help would be greatly appreciated.
[php]
Guest Book form { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: block; width: 100%; max-width: 400px; height: 400px; background-color: orange; padding: 10px; } fieldset.fieldsetStyle { border: 1px solid #fff; height: 360px; padding: 10px; } label.labelStyle, legend.legendStyle { font-family: Arial, Helvetica, sans-serif; font-size: 1.0rem; line-height: 1.5; color: #fff; } legend.legendStyle { padding: 0 10px; } input.inputStyle { clear: right; display: block; width: 100%; max-width: 200px; height: 25px; font-family: Arial, Helvetica, sans-serif; font-size: 0.8em; line-height: 1.0em; color: #000; padding: 0px 5px 0px 5px; margin: 0px; } input.formBtn { border: none; outline: none; background-color: #2e2e2e; color: #fff; width: 75px; height: 25px; margin: 20px 0; } /* Guest Book Display */ ul { border: 1px solid #2e2e2e; width: 500px; height: auto; padding: 10px 20px;} li { list-style: none; text-align: left;} a.record { font-family: Arial, Helvetica, sans-serif; font-size: 1.2rem; line-height: 1.5; text-decoration: none; color: #2e2e2e; } a.record:hover { color: blue; }-
<?php
/* Loop through the records (array record) and Display */
for ($y=0; $y < count($record); $y++) {
- ’ . $entry->fname . ’ ’ . $entry->lname . ’ || Email Address : ’ . $entry->email . ‘ ’ . “\n”;
/* Convert Inner Array to an object $entry where */
/* for example $entry->fname is first name of record */
$entry = (object) $record[$y];
/* Output the Record */
echo ‘
echo “
\n”;
} // End of Loop:
?>
[php]
<?php /* A simple text file */ $file = "guest_book.txt"; $record = array(); /* Save to the text file */ if ( isset($_POST['submit']) && $_POST['submit'] == "Submit" ) { /* Convert to a string, insert , and \n into the string */ $data = $_POST['fname'] . ',' . $_POST['lname'] . ',' . $_POST['email'] . "\n"; /* Save to text file in directory database with file name guest_book.txt */ $result = file_put_contents($file, $data, FILE_APPEND | LOCK_EX); /* Check Results of insert */ if ($result) { $message = $result . ' bytes written to file. '; } else { die('There was an error writing to this file'); } } /* Setup up Display */ if (file_exists($file)) { /* Grab each line of text file in an array */ $records = file($file); /* Explode each line string in the array into an inner array */ foreach ($records as $key => $value) { $output[$key] = explode(",", $value); } /* Convert to associative inner array */ for ( $x = 0; $x < count($output); $x++) { $record[$x]['fname'] = $output[$x][0]; $record[$x]['lname'] = $output[$x][1]; $record[$x]['email'] = $output[$x][2]; } } ?>[/php]
Thank you!