Location: PHPKode > scripts > PHP-AGTC membership system > admin/add_members.php
<?php

  /* Sample Members Admin Area (C) American Financing 2004-2005 */

  require '../mysqlvars.php';
  require '../lib/db.php';
  require '../lib/form_functions.php';

  session_start('ADMIN');

  require 'includes/secure_page.php';

  unset($error);
  unset($confirm);

  if (isset($_POST['submit'])) {
	if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['password2']) || empty($_POST['email'])) {
	  $error = 'You must complete all fields';
	}
	if (!isset($error)) {
	  if ($_POST['password'] != $_POST['password2']) {
		$error = 'Passwords do not match';
	  }
	  if (!isEmail(stripData($_POST['email']))) {
		$error = 'Invalid data in Email - (Email)';
	  }
	}
	if (!isset($error)) {
	  $dbConn = connectDB($dbHost, $dbUser, $dbPass, $dbDB);
	  if ($dbConn) {
		$query = "INSERT INTO wsd_members (username,password,email,registered_on,last_logged_on) VALUES (";
		$query .= "'" . prepareData($_POST['username']) . "'" . ',';
		$query .= "MD5('" . prepareData($_POST['password']) . "')" . ',';
		$query .= "'" . prepareData($_POST['email']) . "'" . ',';
		$query .= 'CURDATE()' . ',';
		$query .= 'NULL';
		$query .= ")";
		if (mysql_query($query,$dbConn)) {
		  $confirm = 'User added';
		  unset($_POST);
		}
		else {
		   $error = mysql_error();
		}
	  }
	  else {
		$error = 'Database is currently unavailable';
	  }
	}
  }
?>
<html>
<head>
<title>Add Members</title>
<META HTTP-EQUIV="PRAGMA" CONTENT="NOCACHE">
<link rel="stylesheet" href="styles/fgp.css" type="text/css">
</head>
<body>
  <table class="bg">
	<tr>
	  <td>
		<table class="fg">
		  <tr>
			<td class="title">Add Members</td>
		  </tr>
		</table>
	  </td>
	</tr>
	<tr>
	  <td>
		<table class="nb">
		  <tr>
			<td><a href="browse_members.php">Browse Members</a></td>
		  </tr>
		</table>
	  </td>
	</tr>
	<tr>
	  <td>
		<table class="nb">
		  <?php if (isset($confirm)) { echo "<tr><td class=\"bold\">$confirm</td><tr>"; } ?>

		  <?php if (isset($error)) { echo "<tr><td class=\"error\">$error</td></tr>"; } ?>

		</table>
	  </td>
	</tr>
	<tr>
	  <td>
		<table class="fg">
		  <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
			<tr>
			  <td class="label">Username:</td>
			  <td class="field">
				<input type="text" name="username" size="20" maxlength="20" value="<?php if (isset($_POST['username'])) { echo htmlChars($_POST['username']); } ?>">
			  </td>
			</tr>
			<tr>
			  <td class="label">Password:</td>
			  <td class="field">
				<input type="password" name="password" size="16" maxlength="16" value="<?php if (isset($_POST['password'])) { echo htmlChars($_POST['password']); } ?>">
			  </td>
			</tr>
			<tr>
			  <td class="label">Re-enter Password:</td>
			  <td class="field">
				<input type="password" name="password2" size="16" maxlength="16" value="<?php if (isset($_POST['password'])) { echo htmlChars($_POST['password']); } ?>">
			  </td>
			</tr>
			<tr>
			  <td class="label">Email:</td>
			  <td class="field">
				<input type="text" name="email" size="20" maxlength="100" value="<?php if (isset($_POST['email'])) { echo htmlChars($_POST['email']); } ?>">
			  </td>
			</tr>
			<tr><td class="label">&nbsp;</td><td class="field"><input type="Submit" name="submit" value="Submit"></td></tr>
		  </form>
		</table>
	  </td>
	</tr>
  </table>
</body>
</html>

Return current item: PHP-AGTC membership system