Wrox Programmer Forums
|
BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1
This is the forum to discuss the Wrox book Professional PHP5 by Ed Lecky-Thompson, Heow Eide-Goodman, Steven D. Nowicki, Alec Cove; ISBN: 9780764572821
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2009, 05:23 PM
Registered User
 
Join Date: Jan 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP4 to PHP5

I was considering purchasing PHP5 but it looks like the codes are in just as in a mess with PHP5 as the PHP4 book

Example PHP5 register.php Chapter 11
Code:
<?php
//register.php
include_once "./common_db.php";
function in_use($userid) {
   global $user_tablename;
   
   $query = "SELECT userid FROM $user_tablename WHERE userid = '$userid'";
   $result = mysql_query($query);
   if(!mysql_num_rows($result)) return 0;
   else return 1;
}
function register_form() {
global $userposition;
global $PHP_SELF;
$link_id = db_connect();
mysql_select_db("sample_db");
$position_array = enum_options('userposition', $link_id);
mysql_close($link_id);
?>

<CENTER><H3>Create your account!</H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action">
  <DIV ALIGN="CENTER"><CENTER><TABLE BORDER="1" WIDTH="90%">
    <TR>
      <TH WIDTH="30%" NOWRAP>Desired ID</TH>
      <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="userid" 
                             SIZE="8" MAXLENGTH="8"></TD>
    </TR>
    <TR>
      <TH WIDTH="30%" NOWRAP>Desired Password</TH>
      <TD WIDTH="70%"><INPUT TYPE="PASSWORD" 
                             NAME="userpassword" SIZE="15"></TD>
    </TR>
    <TR>
      <TH WIDTH="30%" NOWRAP>Retype Password</TH>
      <TD WIDTH="70%"><INPUT TYPE="PASSWORD" 
                             NAME="userpassword2" SIZE="15"></TD>
    </TR>
    <TR>
      <TH WIDTH="30%" NOWRAP>Full Name</TH>
      <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="username" SIZE="20"></TD>
    </TR>
    <TR>
      <TH WIDTH="30%" NOWRAP>Position</TH>
      <TD WIDTH="70%"><SELECT NAME="userposition" SIZE="1">
<?php

   for($i=0; $i < count($position_array); $i++) {
    if(!isset($userposition) && $i == 0) {
      echo "<OPTION SELECTED VALUE=\"". $position_array[$i] .
           "\">" . $position_array[$i] . "</OPTION>\n";
    }
    else if($userposition == $cposition_array[$i]) {
      echo "<OPTION SELECTED VALUE=\"". $position_array[$i] . "\">" .
                                        $position_array[$i] . "</OPTION>\n";
    }
    else {
      echo "<OPTION VALUE=\"". $position_array[$i] . "\">" .
                               $position_array[$i] . "</OPTION>\n";
    }
  }
?>

      </SELECT></TD>
    </TR>
    <TR>
      <TH WIDTH="30%" NOWRAP>Email</TH>
      <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="useremail" SIZE="20"
      </TD>
    </TR>
    <TR>
      <TH WIDTH="30%" NOWRAP>Profile</TH>
      <TD WIDTH="70%"><TEXTAREA ROWS="5" COLS="40" 
                                NAME="userprofile"></TEXTAREA></TD>
    </TR>
    <TR>
      <TH WIDTH="30%" COLSPAN="2" NOWRAP>
        <INPUT TYPE="SUBMIT" VALUE="Submit">
        <INPUT TYPE="RESET" VALUE="Reset"></TH>
    </TR>
  </TABLE>
  </CENTER></DIV>
</FORM>
<?php
}
function create_account() {
   $userid = $_POST['userid'];
   $username = $_POST['username'];
   $userpassword = $_POST['userpassword'];
   $userpassword2 = $_POST['userpassword2'];
   $userposition = $_POST['userposition'];
   $useremail = $_POST['useremail'];
   $userprofile = $_POST['userprofile'];
   global $default_dbname, $user_tablename;

   if(empty($userid)) error_message("Enter your desired ID!");
   if(empty($userpassword)) error_message("Enter your desired password!");
   if(strlen($userpassword) < 4 ) error_message("Password too short!");
   if(empty($userpassword2)) 
                  error_message("Retype your password for verification!");
   if(empty($username)) error_message("Enter your full name!");
   if(empty($useremail)) error_message("Enter your email address!");
   if(empty($userprofile)) $userprofile = "No Comment.";
   
   if($userpassword != $userpassword2)
      error_message("Your desired password and retyped password mismatch!");
   

   $link_id = db_connect($default_dbname);
   
   if(in_use($userid))
         error_message("$userid is in use. Please choose a different ID.");

   $query = "INSERT INTO user VALUES(NULL, '$userid', password('$userpassword'), 
                     '$username', '$userposition', '$useremail', '$userprofile')";
   $result = mysql_query($query);
   if(!$result) error_message(sql_error());

   $usernumber = mysql_insert_id($link_id);
   html_header();
?>   

<CENTER><H3>
<?php echo $username ?>, thank you for registering with us!
</H3></CENTER>
<DIV ALIGN="CENTER"><CENTER><TABLE BORDER="1" WIDTH="90%">
  <TR>
    <TH WIDTH="30%" NOWRAP>User Number</TH>
    <TD WIDTH="70%"><?php echo $usernumber ?></TD>
  </TR>
  <TR>
    <TH WIDTH="30%" NOWRAP>Desired ID</TH>
    <TD WIDTH="70%"><?php echo $userid ?></TD>
  </TR>
  <TR>
    <TH WIDTH="30%" NOWRAP>Desired Password</TH>
    <TD WIDTH="70%"><?php echo $userpassword ?></TD>
  </TR>
  <TR>
    <TH WIDTH="30%" NOWRAP>Full Name</TH>
    <TD WIDTH="70%"><?php echo $username ?></TD>
  </TR>
  <TR>
    <TH WIDTH="30%" NOWRAP>Position</TH>
    <TD WIDTH="70%"><?php echo $userposition ?></TD>
  </TR>
  <TR>
    <TH WIDTH="30%" NOWRAP>Email</TH>
    <TD WIDTH="70%"><?php echo $useremail ?></TD>
  </TR>
  <TR>
    <TH WIDTH="30%" NOWRAP>Profile</TH>
    <TD WIDTH="70%"><?php echo htmlspecialchars($userprofile) ?></TD>
  </TR>
</TABLE>
</CENTER></DIV>
<?php
 html_footer();
}
if (empty($_POST)) $_POST['action'] = "";
switch($_POST['action']) {
   case "register": 
      create_account();
   break;
   default:
      html_header();
      register_form();
      html_footer();
   break;
}
?>
My server has
PHP Version 4.4.8

The Beginner PHP4 book (register.php) chapter 13 p468 the script fails. In the beginner PHP5 book (register.php) chapter 11 also fails.

If PHP4 is today too loose for my present server PHP5 I assume must be too tight

What corrections to the above script will mak it work.

There are no error messages when I submit the form it just returns back to the form with a blank form. And it fails to add data to the database.

I'm guessing but could the problem be with the paths to the common_db.inc file?





Similar Threads
Thread Thread Starter Forum Replies Last Post
php4 or php5 dreadzz BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 July 15th, 2005 04:58 AM
php5 - chap5 iris_see BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 March 30th, 2005 09:33 PM
PHP4 & PHP5 sumu Beginning PHP 4 November 7th, 2004 07:30 AM
how do you uninstall php5? cardme42 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 September 2nd, 2004 09:42 PM
Migrate php4.x to php5.x in redhat linux 9 kumarranganath PHP How-To 2 August 18th, 2004 02:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.