Registration UH Username

Send Snippet To: Save this snippet to Code Collector Pro -- view all bassglider's snippets
language: PHP
license: Other

Code for Snippet:

                
<?php
 
if (!isset($_POST['submit'])) {
 
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
 
<html>
<head>
<title>UH Username Request Form</title>
 
<BODY>
<div class=\"title\">
University of Hawai'i Information Technology Services <BR>
Department UH Username Request Form<BR><BR>
</div>
 
<form action=\"/registration.php\" method = \"POST\">
 
<LABEL for=\"Name\">Name: </LABEL>
	<INPUT type=\"text\" id=\"Name\"><BR>
 
<LABEL for=\"Date\">Date: </LABEL>
	<INPUT type=\"text\" id=\"Date\"><BR>
 
<LABEL for=\"UH Number\">UH Number: </LABEL>
	<INPUT type=\"text\" id=\"UH Number\"><BR>
 
<LABEL for=\"Name Of Department\">Name Of Department: </LABEL>
	<INPUT type=\"text\" id=\"Name Of Department\"><BR>
 
<LABEL for=\"Campus Address\">Campus Address: </LABEL>
	<INPUT type=\"text\" id=\"Campus Address\"><BR>
 
<LABEL for=\"Campus Phone\">Campus Phone: </LABEL>
	<INPUT type=\"text\" id=\"Campus Phone\"><BR>
 
<LABEL for=\"Fax\">Fax: </LABEL>
	<INPUT type=\"text\" id=\"Fax\"><BR>
 
Please Check One:<br>
<input type=\"checkbox\" name=\"Field1\" value=\"New\">New<br>
<input type=\"checkbox\" name=\"Field1\" value=\"Renewal\">Renewal<br>
<input type=\"checkbox\" name=\"Field1\" value=\"Change Owner\">Change Owner<br>
<input type=\"checkbox\" name=\"Field1\" value=\"Update\">Update<br>
<input type=\"checkbox\" name=\"Field1\" value=\"Instructional Course\">Instructional Course<br>
 
<input type=\"submit\" value=\"Submit\" name=\"submit\">
 
</form>
 
</BODY>
</HTML>";
 
exit();
}
 
// Stick POST data into variables:
 
if (isset($_POST['Name'])) {
	$Name = $_POST['Name'];
	}else { echo "You forgot to enter your name!"; exit(); }
 
if (isset($_POST['Date'])) {
	$Date = $_POST['Date'];
	} else { echo "You forgot to enter your Date!"; exit(); }
 
if (isset($_POST['UH Number'])) {
	$UH = $_POST['UH Number'];
	} else { echo "You forgot to enter your UH Number!"; exit(); } 
 
if (isset($_POST['Name Of Department'])) {
	$DeptName = $_POST['Name Of Department'];
	} else { echo "You forgot to enter the name of your department!"; exit(); } 
 
if (isset($_POST['Campus Address'])) {
	$CampAddr = $_POST['Campus Address'];
	} else { echo  "You forgot to enter your Campus Address!"; exit(); } 
 
if (isset($_POST['Campus Phone'])) {
	$CampPhne = $_POST['Campus Phone'];
	} else { echo "You forgot to enter your Campus Phone Number!"; exit(); } 
 
if (isset($_POST['Fax'])) {
	$Fax = $_POST['Fax'];
	} else { echo "You forgot to enter your Fax Number!"; exit(); } 
 
if (isset($_POST['Field1'])) {
	$Field1 = $_POST['Field1'];
	} else { echo "You must check one box!"; exit(); } 
 
// Check to see whats in the Database.
// 'UH Number' is the primary key at the moment
 
// Connect to database
mysql_connect("localhost", "root", "password");
mysql_select_db("personaldetails");
 
// Formulate Query To Grab Existing stuff
$query = sprintf("SELECT Name, Date, UH, DeptName, CampAddr, CampPhne, Fax, Field1 FROM pdetails WHERE UH='%s'", 
mysql_real_escape_string($UH));
 
// Perform Query 
$result = mysql_query($query);
 
// Check result for error (in case of bad query due to malformed POST data)
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
 
// check if data exists
while ($row = mysql_fetch_assoc($result)) {
	$dbName = $row['Name'];
	$dbDate = $row['Date'];
	$dbUH = $row['UH'];
	$dbDeptName = $row['DeptName'];
	$dbCampAddr = $row['CampAddr'];
	$dbCampPhne = $row['CampPhne'];
	$dbFax = $row['Fax'];
	$dbField1 = $row['Field1'];
}
 
if (isset($dbName)) { 
	$status="exists"; 
} 
 
if ($status="exists") {
	echo " The UH number you entered ($dbUH) already exists!"; exit();
}
 
// Now stuff new data into database
$query = "INSERT INTO pdetails (Name, Date, UH, DeptName, CampAddr, CampPhne, Fax, Field1) VALUES ('$Name', '$Date', '$UH', '$DeptName', '$CampAddr', '$CampPhne', '$Fax', '$Field1')";
mysql_query($query);
 
echo "Data Added!";
 
exit();
?>
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 3160
Date Added: 2008-03-20 01:38:41
Last Modified: 0000-00-00 00:00:00

Web Analytics