hi all,i'm very new in php :D.so i copied these code from Wrox BegPHP5 book..and implement as a testing but this s not given me the result when i put all the fileds for user registration..why??..the code s here
//include file. common_db.inc
<?php
$dbhost = 'localhost';
$dbusername = 'phpuser';
$dbuserpassword = 'phppass';
$default_dbname = 'sample_db';
$records_per_page = 5;
$user_tablename = 'user';
$access_log_tablename = 'access_log';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
$new_win_width = 600;
$new_win_height = 400;
html_header();
function html_header()
{
global $new_win_width, $new_win_height;
?>
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript" >
<!--
function open_window(url)
{
var NEW_WIN = null;
NEW_WIN =window.open("" ,"RecordViewer","toolbar=no,width="+ <?php echo $new_win_width ?> + ",directories=no,status=no"+",directories=no, status=no"+", scrollbars=yes,resize=no,menubar=no");
NEW_WIN.location.href = url;
}
//-->
</script>
<title>User Record Viewer</title>
<head></head>
<body>
<?php
}
function html_footer()
{
?>
</body>
</html>
<?php
}
function db_connect()
{
global $dbhost,$dbusername,$dbuserpassword,$default_dbnam e;
global $MYSQL_ERRNO,$MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername,$dbuserpassword);
if(!$link_id)
{
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection Failed to the host $dbhost";
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname))
{
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error()
{
global $MYSQL_ERRNO,$MYSQL_ERROR;
if(empty($MYSQL_ERROR))
{
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO:$MYSQL_ERROR";
}
function error_message($msg)
{
html_header();
echo "<script>alert(\"Error:$msg\");history.go(-1)</script>";
html_footer();
exit;
}
function enum_options($field, $link_id) {
$query = "SHOW COLUMNS FROM user LIKE '$field'";
$result = mysql_query($query, $link_id);
$query_data = mysql_fetch_array($result);
if(eregi("('.*')", $query_data["Type"], $match)) {
$enum_str = ereg_replace("'", "", $match[1]);
$enum_options = explode(',', $enum_str);
return $enum_options;
} else return 0;
}
?>
and register.php code here.......
<?php
include "./common_db.inc";
function in_use($userid)
{
$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="nowrap">Desired ID </th>
<td width="70%" ><input type="text" name="userid" size="8" maxlength="8" /></td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">Desire Password </th>
<td width="70%" ><input type="password" name="userpassword" size="15" /></td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">Retype Password </th>
<td width="70%"><input type="password" name="userpassword2" size="15" /></td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">Full Name</th>
<td width="70%" ><input type="text" name="username" size="20" /></td>
</tr>
<tr>
<th width="30%" nowrap="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="nowrap">Email</th>
<td width="70%"><input type="text" name="useremail" size="20" /></td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">Profile</th>
<td width="70%"><textarea rows="5" cols="40" name="userprofile" ></textarea>
</td>
</tr>
<tr>
<th width="30%" colspan="2" nowrap="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 Desire ID!");
if(empty($username)) error_message ("Enter your Name !");
if(strlen($userpassword) < 4 ) error_message("Password is too Short!");
if(empty($userpassword2)) error_message("Enter your password for Verification!");
if(empty($userposition)) error_message("Please fill your Position!");
if (empty($useremail)) error_message("Give your E-mail ID!");
if(empty($userprofile)) $userprofile = "No Comment.";
if($userpassword2 != $userpassword) error_message ("Your Retype password and desired password mismatch");
$link_id = db_connect($default_dbname);
if(in_use($userid)) error_message ("Please choose another ID $userid is already in use!");
$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 ?>, Welcome for Registering with us!
</h3></center>
<div align="center"><center><table border="1" width="90%">
<tr>
<th width="30%" nowrap="nowrap">User Number</th>
<td width="70%"><?php echo $usernumber ?> </td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">Desired ID</th>
<td width="70%"><?php echo $userid ?> </td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">User Password</th>
<td width="70%"><?php echo $userpassword ?> </td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">Full Name</th>
<td width="70%"><?php echo $username ?></td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">User Position</th>
<td width="70%"><?php echo $userposition ?> </td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">User E-mail</th>
<td width="70%"><?php echo $useremail ?> </td>
</tr>
<tr>
<th width="30%" nowrap="nowrap">User 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;
}
?>

now what i can do with dis??