Jump to content

user registation form


gcpaul

Recommended Posts

page1
<?php
//connect to MySQL; note we have used our own parameters- you should use
//your own for hostname, user, and password
$connect = mysql_connect("localhost", "root", "pass") or
die ("Hey loser, check your server connection.");

//create the main database if it doesn't already exist
$create = mysql_query("CREATE DATABASE IF NOT EXISTS registration")
or die(mysql_error());

//make sure our recently created database is the active one
mysql_select_db("registration");


//create "user_info" table
$user_info = "CREATE TABLE user_info (
userName varchar(255) NOT NULL,
password varchar(10) NOT NULL,
gender ENUM('male','female') NOT NULL,
hobby varchar(20) default NULL,
interest varchar(50) default NULL,
subInterestA varchar(50) default NULL,
subInterestB varchar(50) default NULL,

id int(10) NOT NULL,
)";

$results = mysql_query($user_info)
or die(mysql_error());


$insert = "INSERT INTO admin( userName , password , gender , admin_level, id)".
"VALUES('johndoe' , 'john doe', 'john@johndoe.com' , PASSWORD('jane') , 'male' , '1' ,'')".
"('janedoe' , 'jane doe' , 'jane@jane.doe' , PASSWORD('john') , 'female' , '2' , '')".
$results = mysql_query($insert)
or die(mysql_error());
echo "Registration Database successfully created!";

?>
page2

<?php
session_start();
ob_start();
include "conn.inc.php";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="description" content=" ">
<meta name="keywords" content=" ">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>form</title>
<style type="text/css">
#frm{
position: absolute;
left: 141px;
top: 150px;
width: 300px;
height: 250px}
.frm002{width: 115px}
</style>
<script language="javascript">
var subInterestsA = Object();
subInterestsA['Computer'] = '|Hardware|Software|Networking|Multimedia|Troubleshooting|Other';
subInterestsA['Other'] = '|Other';

var subInterestsB = Object();
subInterestsB['Hardware']='|Processor|Motherboard|Monitor|hdd|fdd|cd|keybord|ups|modem|Other';
subInterestsB['Software']='|cpp|java|vb|vb.net|vb script|java script|asp|jsp|php|jsf|Other';
subInterestsB['Networking']='|lan|wan|Other';
subInterestsB['Multimedia']='|movies|game|mixing|Other';
subInterestsB['Troubleshooting']='|cpu trouble|monitor trouble|soft trouble|Other';
subInterestsB['Other']='|Other';
function setInterests()
{
for (interest in subInterestsA)
document.write('<option value="' + interest + '">' + interest + '</option>');
}

function set_subInterestA(oInterestSel, oSubInterestASel, oSubInterestBSel)
{
var subInterestAArr;
oSubInterestASel.length = 0;
oSubInterestBSel.length = 0;
var interest = oInterestSel.options[oInterestSel.selectedIndex].text;
if (subInterestsA[interest])
{
oSubInterestASel.disabled = false;
oSubInterestBSel.disabled = true;
oSubInterestASel.options[0] = new Option('SELECT INTEREST','');
subInterestAArr = subInterestsA[interest].split('|');
for (var i = 0; i < subInterestAArr.length; i++)
oSubInterestASel.options[i + 1] = new Option(subInterestAArr[i], subInterestAArr[i]);
}
else oSubInterestASel.disabled = true;
}
function set_subInterestB(oSubInterestASel, oSubInterestBSel)
{
var subInterestBArr;
oSubInterestBSel.length = 0;
var subInterestA = oSubInterestASel.options[oSubInterestASel.selectedIndex].text;
if (subInterestsB[subInterestA])
{
oSubInterestBSel.disabled = false;
oSubInterestBSel.options[0] = new Option('SELECT INTEREST','');
subInterestBArr = subInterestsB[subInterestA].split('|');
for (var i = 0; i < subInterestBArr.length; i++)
oSubInterestBSel.options[i+1] = new Option(subInterestBArr[i],subInterestBArr[i]);
}
else oSubInterestBSel.disabled = true;
}

function print_subInterestB(oSubInterestASel, oSubInterestBSel)
{
var subInterestA = oSubInterestASel.options[oSubInterestASel.selectedIndex].text;
var subInterestB = oSubInterestBSel.options[oSubInterestBSel.selectedIndex].text;
}

</script>
</head>
<body>
<?php
if (isset($_POST['submit']) && $_POST['submit'] == "Register") {
if ($_POST['username'] != "" &&
$_POST['password'] != "" &&
$_POST['gender'] != "" &&
$_POST['hobby'] != "" &&
$_POST['interest'] != "" &&
$_POST['subInterestA'] != "" &&
$_POST['subInterestB'] != "") {

$query = "SELECT username FROM user_info " .
"WHERE username = '" . $_POST['username'] . "';";
$result = mysql_query($query)
or die(mysql_error());

if (mysql_num_rows($result) != 0) {
?>

<font color="#FF0000"><b>The Username,
<?php echo $_POST['username']; ?>, is already in use, please choose
another!</b></font>
<form id="frm" method="POST" action="register.php" autocomplete="off">
<table border="1" width="100%" id="table1">
<tr>
<td class="frm002">Password:</td>
<td><input type="text" name="username" value="<?php echo $_POST['password']; ?>" size="20"></td>
</tr>
<tr>
<td class="frm002">Gender:</td>
<td><input type="radio" value="<?php echo $_POST['male']; ?>" name="gender">Male<input type="radio" name="gender" value="<?php echo $_POST['female']; ?>">Female</td>
</tr>
<tr>
<td class="frm002">Hobby:</td>
<td><select size="1" name="hobby">
<option value="<?php echo $_POST['hobby']; ?>">select hobby</option>
<option value="sports">sports</option>
<option value="reading">reading</option>
<option value="movies">movies</option>
<option value="songs">songs</option>
<option value="writing">writing</option>
<option value="yoga">yoga</option>
</select></td>
</tr>
<tr>
<td class="frm002">Interest:</td>
<td>
<select onchange="set_subInterestA(this,subInterestA,subInterestB)" size="1" name="interest">
<option>SELECT INTEREST</option>
<option value="<?php echo $_POST['interest']; ?>"></option>
<script type="text/javascript">
setInterests(this);
</script>
</select></td>
</tr>
<tr>
<td class="frm002" rowspan="2">&nbsp;</td>
<td><select size="1" name="subInterestA" disabled="disabled" onchange="set_subInterestB(this,subInterestB)">
<option value="<?php echo $_POST['subInterestA']; ?>">&lt;--------------------------&gt;</option>
</select></td>
</tr>
<tr>
<td><select size="1" name="subInterestB" disabled="disabled" onchange="print_subInterestB(subInterestA,this)">
<option value="<?php echo $_POST['subInterestB']; ?>">&lt;--------------------------&gt;</option>
</select></td>
</tr>
</table>

<input type="checkbox" name="C1" value="ON">
I affirm that I accept terms and condition.

<p><input type="submit" value="register" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<?php
} else {
$query = "INSERT INTO user_info (username, gender, hobbies) " .
"VALUES ('" . $_POST['username'] . "',
'" . $_POST['password'] . "',
'" . $_POST['gender'] . "',
'" . $_POST['hobby'] . "',
'" . $_POST['interest'] . "',
'" . $_POST['subInterestA'] . "',
'" . $_POST['subInterestB'] . "');";
$result = mysql_query($query)
or die(mysql_error());
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
?>
<p>
Thank you, <?php echo $_POST['username']; ?> for registering!<br>
<?php
header("Refresh: 5; URL=index.php");
echo "Your registration is complete! " .
"You are being sent to the page you requested!<br>";
echo "(If your browser doesn't support this, " .
"<a href=\"index.php\">click here</a>)";
die();
}
} else {
?>
<font color="#FF0000"><b>All fields are required!</b></font>
<form id="frm" method="POST" action="register.php" autocomplete="off">
<table border="1" width="100%" id="table1">
<tr>
<td class="frm002">User Name:</td>
<td><input type="text" name="username" value="<?php echo $_POST['username']; ?>" size="20"></td>
</tr>
<tr>
<td class="frm002">Password:</td>
<td><input type="password" name="password" value="<?php echo $_POST['password']; ?>" size="20"></td>
</tr>

<tr>
<td class="frm002">Gender:</td>
<td><input type="radio" value="<?php echo $_POST['male']; ?>" name="gender">Male<input type="radio" name="gender" value="<?php echo $_POST['female']; ?>">Female</td>
</tr>
<tr>
<td class="frm002">Hobby:</td>
<td><select size="1" name="hobby">
<option value="<?php echo $_POST['hobby']; ?>">select hobby</option>
<option value="sports">sports</option>
<option value="reading">reading</option>
<option value="movies">movies</option>
<option value="songs">songs</option>
<option value="writing">writing</option>
<option value="yoga">yoga</option>
</select></td>
</tr>
<tr>
<td class="frm002">Interest:</td>
<td>
<select onchange="set_subInterestA(this,subInterestA,subInterestB)" size="1" name="interest">
<option>SELECT INTEREST</option>
<option value="<?php echo $_POST['interest']; ?>"></option>
<script type="text/javascript">
setInterests(this);
</script>
</select></td>
</tr>
<tr>
<td class="frm002" rowspan="2">&nbsp;</td>
<td><select size="1" name="subInterestA" disabled="disabled" onchange="set_subInterestB(this,subInterestB)">
<option value="<?php echo $_POST['subInterestA']; ?>">&lt;--------------------------&gt;</option>
</select></td>
</tr>
<tr>
<td><select size="1" name="subInterestB" disabled="disabled" onchange="print_subInterestB(subInterestA,this)">
<option value="<?php echo $_POST['subInterestB']; ?>">&lt;--------------------------&gt;</option>
</select></td>
</tr>
</table>

<input type="checkbox" name="C1" value="ON">
I affirm that I accept terms and condition.

<p><input type="submit" value="register" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<?php
}
} else {
?>
<form id="frm" method="POST" action="register.php" autocomplete="off">
<table border="1" width="100%" id="table1">
<tr>
<td class="frm002">User Name:</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td class="frm002">Password:</td>
<td><input type="password" name="password" size="20"></td>
</tr>

<tr>
<td class="frm002">Gender:</td>
<td><input type="radio" value="male" name="gender">Male<input type="radio" name="gender" value="female">Female</td>
</tr>
<tr>
<td class="frm002">Hobby:</td>
<td><select size="1" name="hobby">
<option value="hobby">select hobby</option>
<option value="sports">sports</option>
<option value="reading">reading</option>
<option value="movies">movies</option>
<option value="songs">songs</option>
<option value="writing">writing</option>
<option value="yoga">yoga</option>
</select></td>
</tr>
<tr>
<td class="frm002">Interest:</td>
<td>
<select onchange="set_subInterestA(this,subInterestA,subInterestB)" size="1" name="interest">
<option>SELECT INTEREST</option>
<option value="interest"></option>
<script type="text/javascript">
setInterests(this);
</script>
</select></td>
</tr>
<tr>
<td class="frm002" rowspan="2">&nbsp;</td>
<td><select size="1" name="subInterestA" disabled="disabled" onchange="set_subInterestB(this,subInterestB)">
<option value="subInterestA">&lt;--------------------------&gt;</option>
</select></td>
</tr>
<tr>
<td><select size="1" name="subInterestB" disabled="disabled" onchange="print_subInterestB(subInterestA,this)">
<option value="subInterestB">&lt;--------------------------&gt;</option>
</select></td>
</tr>
</table>

<input type="checkbox" name="C1" value="ON">
I affirm that I accept terms and condition.



<p><input type="submit" value="register" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<?php
}
?>

</body>

</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.