Hi there Arth,
I didn't mean it in a bad way. It's just that all of your TH errors were identical, so I thought that you copied & pasted the html portion. I do it all the time. It's handy..
As for your problem. I found it, but I think you would have found it yourself had you formatted your code to make it easier to read:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
//register.php
include_once "./common_db.inc";
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();
$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"></td>
</tr>
<tr>
<th width="30%" nowrap>Desired 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>
<td 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]."</td>OPTION>\n";
}
}
?>
</select></td>
</tr>
<tr>
<th width="30%" nowrap>Email</th>th>
<td width="70%"><input type="text" name="useremail" size="20"
</td>
</tr>
<tr>
<th width="30%" nowrap>Profile</th>th>
<td WIDTH="70%"><textarea rows="5" cols="40" name="userprofile"></textarea>textarea></tr>
</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 yur desired ID!");
}
if(empty($userpassword)){
error_message("Enter your 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(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; ?>jhjkkkjkh</td>
</tr>
<tr>
<th width="30%" nowrap>Desired Password</th>
<td width="70%"><?php echo $userpassword; ?></td>
<tr>
<th width="30%" nowrap>Full name</th>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>
<th width="30%" nowrap>Profile</th>
<td width="30%" nowrap><?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;
}
?>
</form>
</body>
</html>
The way I indented your conditional statements and functions lets you see really quick when you've forgotten an ending bracket.
if(empty($useremail)){
error_message("Enter your email address!");
if(empty($userprofile)){
$userprofile="No comment";
}
should have been:
if(empty($useremail)){
error_message("Enter your email address!");
if(empty($userprofile)){
$userprofile="No comment";
}
}
You should be able to run your code now. If you format it this way, it will help you a lot when it comes time to debug.
thanks,
json