Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 27th, 2006, 02:17 PM
Authorized User
 
Join Date: Nov 2005
Location: UTTARKASHI, , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 12 modified register.php problem

I have modified register.php and registration.php. can anybody help me to locate mistakes:
here is REGISTER.PHP:
<?php
session_start();
ob_start();
include "conn.inc.php";
?>
<html>
<head>
<title>Beginning PHP5, Apache and MySQL</title>
</head>
<script language="javascript">
var subInterestsA = Object();
subInterestsA['Computer'] = '|Hardware|Software|Networking|Multimedia|Troubles hooting|Other';
subInterestsA['Other'] = '|Other';

var subInterestsB = Object();
subInterestsB['Hardware']='|Processor|Motherboard|Monitor|hdd|fdd|cd|keybor d|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>
  <b>The Username,
  <?php echo $_POST['username']; ?>, is already in use, please choose
  another!</b>
  <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,subIn terestB)" 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>
  <b>The Username, Password, Email, First Name,
  and Last Name fields are required!</b>
  <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,subIn terestB)" 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,subIn terestB)" 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!";

?>


Reply With Quote
  #2 (permalink)  
Old June 6th, 2006, 03:41 PM
Registered User
 
Join Date: Dec 2004
Location: Vanloese, , Denmark.
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi

What is the problem? What does the parser say. I might be able to help, but this is a bit like a needle in tha famous haystack.

Best Regards,
Hanne B. Stegemüller - Denmark
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 12/register/user_login airtime373 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 April 7th, 2008 08:14 PM
chapter 12 modified register.php problem GOUR CHANDRA PAUL BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 April 27th, 2006 02:14 PM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 09:57 AM
Chapter 12 - useraccount.php buzzuh BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 September 3rd, 2004 02:53 PM
Table join problem Chapter 12, p 436 PHP-Beg tomasz BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 August 31st, 2003 12:56 PM



All times are GMT -4. The time now is 02:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.