No one in the Newbies section was able to help me with this...perhaps someone here might.
The code below doesn't do anything upon the submit button but restart the page. I can't figure out why.
<?php // Script 11.6 - register.php
// This script displays and handles an HTML form.
// This script registers a user by storing their information in a text file and creating a directory for them.
// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset ($_POST['submit'])) { // Handle form.
$problem = FALSE; // No problems so far.
// Check for each value.
if (empty ($_POST['username'])) {
$problem = TRUE;
print '<p>Please enter a username!</p>';
}
if (empty ($_POST['password1'])) {
$problem = TRUE;
print '<p>Please enter a password!</p>';
}
if ($_POST['password1'] != $_POST['password2']) {
$problem = TRUE;
print '<p>Your password did not match your confirmed password!</p>';
}
if (!$problem) { // If there weren't any problems...
if ($fp = fopen ('/users/accounts.txt', 'ab')) { // Open the file.
// Create the data to be written.
$dir = time() . rand (0, 4596);
$data = $_POST['username'] . "\t" . crypt($_POST['password1']) . "\t" . $dir . "\n"; // \r\n on Windows
// Write the data and close the file.
fwrite ($fp, $data);
fclose ($fp);
// Create the directory.
mkdir ("/users/$dir");
// Print a message.
print '<p>You are now registered!</p>';
} else { // Couldn't write to the file.
print '<p>You could not be registered due to a system error.</p>';
}
} else { // Forgot a field.
print '<p>Please try again!</p>';
}
} else { // Display the form.
// Leave PHP and display the form.
?>
<form action="register.php" method="post" name="form1" id="form1" onsubmit="MM_validateForm('username','','R','fname','','R','lname','','R','email','','RisEmail','password1','','R','password2','','R');return document.MM_returnValue">
<table width="337" border="0">
<tr>
<td width="137"><div align="right"><span class="style7">
</span></div> <span class="style7"><label>
<div align="right">Username:</div>
</label>
</span></td>
<td width="190">
<input name="User Name" id="username" type="text" size="25" /> </td>
</tr>
<tr>
<td><div align="right"><span class="style7">
</span></div> <span class="style7"><label>
<div align="right">First Name:</div>
</label>
</span></td>
<td>
<input name="First Name" id="fname" type="text" size="25" /> </td>
</tr>
<tr>
<td><div align="right"><span class="style7">
</span></div> <span class="style7"><label>
<div align="right">Last Name:</div>
</label>
</span></td>
<td>
<input name="Last Name" id="lname" type="text" size="25" /> </td>
</tr>
<tr>
<td><div align="right"><span class="style7">
</span></div> <span class="style7"><label>
<div align="right">Email Address:</div>
</label>
</span></td>
<td>
<input name="Email" id="email" type="text" size="25" /> </td>
</tr>
<tr>
<td><div align="right"><span class="style7">
</span></div> <span class="style7"><label>
<div align="right">Password:</div>
</label>
</span></td>
<td>
<input name="Password" id="password1" type="password" size="25" /> </td>
</tr>
<tr>
<td><div align="right"><span class="style7">
</span></div> <span class="style7"><label>
<div align="right">Confirm Password:</div>
</label>
</span></td>
<td>
<input name="Password Confirm" id="password2" type="password" size="25" /> </td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Register" />
<input type="reset" name="Submit2" value="Clear" />
</p>
</form>
<?php
}
?>
Thanks in advance!