Jump to content

gcpaul

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gcpaul's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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!"; ?>
  2. 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>
×
×
  • 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.