Jump to content

user registration form


gcpaul

Recommended Posts

hi!
I am unable to retain radio button(gender) and jawa script populated dropdown(interest) in following script. Can any body help me

Here is register.php file:

<?php
session_start();
ob_start();
include "conn.inc.php";
?>
<html>
<head>
<title>Beginning PHP5and MySQL</title>
</head>
<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>

<body>
<?php
if (isset($_POST['submit']) && $_POST['submit'] == "Register") {
if ($_POST['username'] != "" &&
$_POST['password'] != "" &&
$_POST['first_name'] != "" &&
$_POST['last_name'] != "" &&
$_POST['email'] != "") {

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

if (mysql_num_rows($result) != 0) {
?>
<p>
<font color="#FF0000"><b>The Username,
<?php echo $_POST['username']; ?>, is already in use, please choose
another!</b></font>
<form action="register.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"
value="<?php echo $_POST['password']; ?>"><br>
Email: <input type="text" name="email"
alue="<?php echo $_POST['email']; ?>"><br>
First Name: <input type="text" name="first_name"
value="<?php echo $_POST['first_name']; ?>"><br>
Last Name: <input type="text" name="last_name"
value="<?php echo $_POST['last_name']; ?>"><br>
Gender:<input type="radio" name="gender" value="<?php echo $_POST['gender']; ?>1">Male<input type="radio" name="gender" value="<?php echo $_POST['gender']; ?>2">Female<br>
Interest:<select onchange="set_subInterestA(this,subInterestA,subInterestB)" size="1" name="interest">
<option><?php echo $_POST['inteest']; ?></option>
<option value="interest"></option>
<script type="text/javascript">
setInterests(this);
</script>
</select><br>
<select size="1" name="subInterestA" disabled="disabled" onchange="set_subInterestB(this,subInterestB)">
<option value="subInterestA"><?php echo $_POST['subInterestA']; ?></option>
</select><br>
<select size="1" name="subInterestB" disabled="disabled" onchange="print_subInterestB(subInterestA,this)">
<option value="subInterestB"><?php echo $_POST['subInterestB']; ?></option>
</select><br>
City: <input type="text" name="city"
value="<?php echo $_POST['city']; ?>"><br>
State: <input type="text" name="state"
value="<?php echo $_POST['state']; ?>"><br>
Hobbies:
<select name="hobbies0" size="1">
<option value=""><?php echo $_POST['hobbies']; ?></option>
<option value="Golfing">Golfing</option>
<option value="Hunting">Hunting</option>
<option value="Reading">Reading</option>
<option value="Dancing">Dancing</option>
<option value="Internet">Internet</option>
<option value="Flying">Flying</option>
<option value="Traveling">Traveling</option>
<option value="Exercising">Exercising</option>
<option value="Computers">Computers</option>
<option value="Other Than Listed">Other Than Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Register"> &nbsp;
<input type="reset" value="Clear">
</p>
</form>
</p>
<?php
} else {
$query = "INSERT INTO user_info (username, password, email, " .
"first_name, last_name, city, state, hobbies) " .
"VALUES ('" . $_POST['username'] . "', " .
"(PASSWORD('" . $_POST['password'] . "')), '" .
$_POST['email'] . "', '" . $_POST['first_name'] .
"', '" . $_POST['last_name'] . "',
explode(", ", $_POST['gender']) . "'),
'" . $_POST['interest'] . "',
'" . $_POST['subInterestA'] . "',
'" . $_POST['subInterestA''] .
"','" . $_POST['city'] .
"', '" . $_POST['state'] . "', '" .
$_POST['hobbies']) . "');";
$result = mysql_query($query)
or die(mysql_error());
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
?>
<p>
Thank you, <?php echo $_POST['first_name'] . " " .
$_POST['last_name']; ?> 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 {
?>
<p>
<font color="#FF0000"><b>The Username, Password, Email, First Name,
and Last Name,gender fields are required!</b></font>
<form action="register.php" method="post">
Username: <input type="text" name="username"
value="<?php echo $_POST['username']; ?>"><br>
Password: <input type="password" name="password"
value="<?php echo $_POST['password']; ?>"><br>
Email: <input type="text" name="email"
value="<?php echo $_POST['email']; ?>"><br>
First Name: <input type="text" name="first_name"
value="<?php echo $_POST['first_name']; ?>"><br>
Last Name: <input type="text" name="last_name"
value="<?php echo $_POST['last_name']; ?>"><br>
Gender:<input type="radio" name="gender" value="<?php echo $_POST['gender']; ?>">Male<input type="radio" name="gender" value="<?php echo $_POST['gender']; ?>">Female<br>
Interest:<select onchange="set_subInterestA(this,subInterestA,subInterestB)" size="1" name="interest">
<option><?php echo $_POST['inteest']; ?></option>
<option value="interest"></option>
<script type="text/javascript">
setInterests(this);
</script>
</select><br>
<select size="1" name="subInterestA" disabled="disabled" onchange="set_subInterestB(this,subInterestB)">
<option value="subInterestA"><?php echo $_POST['subInterestA']; ?></option>
</select><br>
<select size="1" name="subInterestB" disabled="disabled" onchange="print_subInterestB(subInterestA,this)">
<option value="subInterestB"><?php echo $_POST['subInterestB']; ?></option>
</select><br>
City: <input type="text" name="city"
value="<?php echo $_POST['city']; ?>"><br>
State: <input type="text" name="state"
value="<?php echo $_POST['state']; ?>"><br>

Hobbies:
<select name="hobbies" size="1">
<option value=""><?php echo $_POST['hobbies']; ?></option>
<option value="Golfing">Golfing</option>
<option value="Hunting">Hunting</option>
<option value="Reading">Reading</option>
<option value="Dancing">Dancing</option>
<option value="Internet">Internet</option>
<option value="Flying">Flying</option>
<option value="Traveling">Traveling</option>
<option value="Exercising">Exercising</option>
<option value="Computers">Computers</option>
<option value="Other Than Listed">Other Than Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Register"> &nbsp;
<input type="reset" value="Clear">
</form>
</p>
<?php
}
} else {
?>
<p>
Welcome to the registration page!<br>
The Username, Password, Email, First Name, and Last Name fields
are required!
<form action="register.php" method="post" autocomplete="off">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
Email: <input type="text" name="email"><br>
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Gender:<input type="radio" name="gender" value="male">Male<input type="radio" name="gender" value="female">Female<br>
Interest:<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><br>
<select size="1" name="subInterestA" disabled="disabled" onchange="set_subInterestB(this,subInterestB)">
<option value="subInterestA">&lt;--------------------------&gt;</option>
</select><br>
<select size="1" name="subInterestB" disabled="disabled" onchange="print_subInterestB(subInterestA,this)">
<option value="subInterestB">&lt;--------------------------&gt;</option>
</select><br>

City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
Hobbies:
<select name="hobbies" size="1">
<option value="Golfing">Golfing</option>
<option value="Hunting">Hunting</option>
<option value="Reading">Reading</option>
<option value="Dancing">Dancing</option>
<option value="Internet">Internet</option>
<option value="Flying">Flying</option>
<option value="Traveling">Traveling</option>
<option value="Exercising">Exercising</option>
<option value="Computers">Computers</option>
<option value="Other Than Listed">Other Than Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Register"> &nbsp;
<input type="reset" value="Clear">
</form>
</p>
<?php
}
?>
</body>
</html>


AND HER IS REGISTRATION .PHP:
<?php
//connect to MySQL; note we?ve used our own parameters- you should use
//your own for hostname, user, and password
$connect = mysql_connect("localhost", "root", '"") 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 "admin" table
$admin = "CREATE TABLE admin(
username varchar(50) NOT NULL,
password varchar(255)NOT NULL,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
email varchar(50) NOT NULL,
gender ENUM('male','female') NOT NULL,
admin_level int(2)NOT NULL,
id int(10) NOT NULL auto_increment,
PRIMARY KEY (id)
)";

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

//create "user_info" table
$user_info = "CREATE TABLE user_info (
email varchar(50) NOT NULL,
username varchar(50) NOT NULL,
password varchar(255) NOT NULL,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
gender ENUM('male','female') NOT NULL,
interest varchar(50) NOT NULL,
subInterestA varchar(50) NOT NULL,
sunInterestB varchar(50) NOT NULL,
city varchar(50) default NULL,
state varchar(50) default NULL,
hobbies varchar(255) default NULL,
id int(10) NOT NULL default '0'
)";

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

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

?>
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.