Registration form( data won't go database)

Hi Guys !
once again need your help, i am working in Registration form, where user put the initial information, however when click the singup nothing happend and
nothing goes to database or no message comes up !
please have look ,

1- Registration file

<?php
//include shard code
include ‘…/lib/common.php’;
include ‘…/lib/db.php’;
include ‘…/lib/function.php’;
include ‘…/lib/user.php’;
//include ‘…/lib/captcha.php’;

//start or continue session so the CAPTCHA text stored in $_SESSION is accessible
session_start();
header(‘Cache-control:private’);
// prepare the registration form’s HTML
ob_start();
?>

<form method=“post” action=
“<?php echo htmlspecialchars($_SERVER[‘PHP_SELF’]);?>”>
<table bordercolor=“#0000CC” bgcolor=“#999999”>
<tr>
<td width=“99”><label for =“username”>Username</label></td>
<td width=“166”><input type=“text” name =“username” id=“username” value=“<?php if(isset($_POST[‘username’])) echo htmlspecialchars ($_POST[‘username’]);?>”/></td>
</tr><tr>
<td><label for=“password1”>Password</label></td>
<td><input type=“password” name=“password1” id=“password1” value=“”/></td></tr>
<td><label for=“password2”>Password Again</label></td>
<td><input type=“password” name=“password2” id=“password2” value=“”/></td></tr>
<td><label for =“email”>Email Address</label></td>
<td><input type =“text” name=“email” id=“email” value =“<?php if($_POST[‘email’])
echo htmlspecialchars ($_POST[‘email’]);?>”/></td></tr><tr>
<td><label for =“captcha” > Verify</label></td>
<td>Enter text seen in this image<br/>
<img src=“…/img/captcha.php?nocache=<?php echo time();?>“alt=”” border=“0”/></a><br/>
<input type=“text” name =“captcha” id=“captcha”/></td></tr><tr>
<td><tr>
<td></td>
<td><input type=“submit” value=“Sign Up”/></td>
<td width=“198”><input type=“hidden” name=“submitted” value=“1”/></td>
</tr><tr>
</table></form>
<?php $form =ob_get_clean();
//show the form if this the first time the page is viewsd
if(!isset($_POST[‘submitted’]))
{//1 on
$GLOBALS[‘TEMPLATE’][‘content’]=$form;
}//1off
//otherwise process incoming data
else
{//2on
//validate password
$password1 =(isset($_POST[‘password1’]))?$_POST[‘password1’]:‘’;
$password2 =(isset($_POST[‘password2’]))?$_POST[‘password2’]:‘’;
$password =($password1 && $password1 == $password2) ? shal($password1):‘’;
// validate CAPTCHA
$captcha =(isset($_POST[‘captcha’]) && strtoupper($_POST[‘captcha’]) == $_SESSION[‘captcha’]);
//add the record if all input validates
if(User::validateUsername($_POST[‘username’]) && password && User::validateEmailAddr($_POST[‘email’]) && $captcha)
{//3on
//make sure the user doesn’t already exist
$user =User::getByUsername($_POST[‘username’]);
if($user->userId)
{//4on
$GLOBALS[‘TEMPLATE’][‘content’]=‘<p><strong>Sorry, that’.‘account already exists.</strong></p> <p>Please try a ‘.’ different username.</p>’;
$GLOBALS[‘TEMPLATE’][‘content’].=$form;
}//2off
else
{//5on
// create an inactive user record
$user = new User();
$user->username = $_POST[‘username’];
$user->password = $password;
$user->emailAddr = $_POST[‘email’];
$token = $user->setInactive();

$message =‘Thank you for singing up for an account ! before you
‘.’ can login you need to verify your account. you can
do’.’ by visitin http://www.mardan.org.uk/user-registration/lib/verify.
php?uid='. $user->userId . ‘$token=’ . $token . ‘.’ ;

if (@mail($user->emailAddr, 'Activate your new account ', $message ))
{
$GLOBALS[‘TEMPLATE’][‘content’] = ‘<p><strong>Thank you for ‘.’
registering .</strong></p> <p> You will be receiving an ‘.’ email shortly with
instructions on
activating your ‘.’ account.</p>’;

}

else

{
$GLOBALS[‘TEMPLATE’][‘content’] = ‘<p><strong>There was an ‘.’ error sending you the
activation link.</strong> </p> ‘.’<p> Please contact the site administration at
<a href="’.‘mailto:kmyousafzai2000@yahoo.com">kmyousafzai2000@yahoo.com</a> for’.’
assistance .</p>';

}}}
}//6off
// display the page
include ‘…/templates/template-page.php’;?>


2- my user file

<?php
class User
{
private $uid; // user id
private $fields; //other record fields
//initialize a User object
public function __construct()
{
$this->uid = null;
$this->fields = array (‘username’=>‘’,
‘password’=>‘’,
‘emailAddr’=>‘’,
‘isActive’=>false);

}
//override magic method to retrieve properties
public function __get ($field)
{
if($field== ‘userId’)
{
return $this->uid;
}
else
{
return $this->fields [$field];
}
}
// override magic method to set properties
public function __set($field,$value)
{
if (array_key_exists($field,$this->fields))
{
$this->fields[$field] =$value ;
}
}
//return if username is valid format
public static function validateUsername ($username)
{
return preg_match (‘/[1] {2,20} $/i’,$username);
}
// return if email address is valid format
public static function validateEmailAddr($email)
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
//return an object populated based on the record’s user id
public static function getById($user_id)
{
$user =new User();
$query = sprintf (‘SELECT USERNAME,PASSWORD,EMAIL_ADDR, IS_ACTIVE’.’ FROM %sWROX_USER WHERE USER_ID = %d’, DB_TBL_PREFIX, $user_id);
$result = mysql_query($query,$GLOBALS[‘DB’]);
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$user->username = $row[‘USERNAME’];
$user->password = $row[‘PASSWORD’];
$user->emailAddr = $row[‘EMAIL_ADDR’];
$user->isActive = $row[‘IS_ACTIVE’];
$user->uid = $user_id;
}
mysql_free_result($result);
return $user;
}
//return an objection populated based on the record’s username
public static function getByUsername ($username)
{
$user = new User();
$query = sprintf (‘SELECT USER_ID, PASSWORD,EMAIL_ADDR,IS_ACTIVE’.‘FROM %sWROX_USER WHERE USERNAME =“%s” ‘, DB_TBL_PREFIX,
mysql_real_escape_string($username,$GLOBALS[‘DB’]));
$result = mysql_query($query,$GLOBALS [‘DB’]);
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$user->username = $username;
$user->password = $row[‘PASSWORD’];
$user->emailAddr = $row[‘EMAIL_ADDR’];
$user->isActive = $row[‘IS_ACTIVE’];
$user->uid = $row[‘USER_ID’];
}
mysql_free_result($result);
return $user;
}
//save the record to the database
public function save()
{
if ($this->uid)
{
$query = sprintf (‘UPDATE %sWROX_USER SET USERNAME = “%s”, ‘.’ PASSWORD = “%s” , EMAIL_ADDR = “%s”, IS_ACTIVE = %d’.’ WHERE USER_ID = %d’, DB_TBL_PREFIX,
mysql_real_escape_string($this->username, $GLOBALS[‘DB’]),
mysql_real_escape_string($this->password, $GLOBALS[‘DB’]),
mysql_real_escape_string($this->emailAddr, $GLOBALS[‘DB’]),
$this->isActive, $this->userId);
return mysql_query($query,$GLOBALS[‘DB’]);
}
else
{
$query = sprintf (‘INSERT INTO %sWROX_USER (USERNAME, PASSWORD,’.’ EMAIL_ADDR, IS_ACTIVE) VALUES (“%s”, “%s”, “%s”, %d)‘, DB_TBL_PREFIX,
mysql_real_escape_string($this->username,$GLOBALS[‘DB’]),
mysql_real_escape_string($this->password,$GLOBALS[‘DB’]),
mysql_real_escape_string($this->emailAddr,$GLOBALS[‘DB’]),
$this->isActive);
if(mysql_query($query,$GLOBALS[‘DB’]))
{
$this->uid = mysql_insert_id($GLOBALS[‘DB’]);
return true;
}
else
{
return false;
}
}
}
// set the record as inactive and return an activation token
public function setInactive()
{
$this-> isActive = false;
$this->save() ;
//make sure the record is saved
$token = random_text(5);
$query =sprintf(‘INSERT INTO %sWROX_PENDING (USER_ID, TOKEN)’.’ VALUES (%d, “%s”)‘, DB_TBL_PREFIX , $this->uid, $token);
return (mysql_query($query,$GLOBALS[‘DB’]))? $token : false ;
}
//clear the user’s pending status and set the reocrd as active
public function setActive($token)
{
$query = sprintf(‘SELECT TOKEN FROM %sWROX_PENDING WHERE USER_ID = %d’.’ AND TOKEN = “%s” ‘,DB_TBL_PREFIX,$this->uid,
mysql_real_escape_string($token,$GLOBALS[‘DB’]));
$result = mysql_query($query,$GLOBALS [‘DB’]);
if(!mysql_num_rows($result))
{
mysql_free_result($result);
return false ;
}
else
{
mysql_free_result($result);
$query = sprintf(‘DELETE FROM %sWROX_PENDING USER_ID = %d’.’ AND TOKEN = “%s”', DB_TBL_PREFIX, $this->uid,
mysql_real_escape_string($token,$GLOBALS[‘DB’]));
if (!mysql_query($query,$GLOBALS[‘DB’]))
{
return false ;
}
else
{
$this->isActive = true;
return $this->save();
}
}
}
}

?>

3- my database (db file)

<?php
//database connection and schema constants
define(‘DB_HOST’,‘localhost’);
define(‘DB_USER’,*);
define(‘DB_PASSWORD’,'
);
define(‘DB_SCHEMA’,‘mardan_table’);
define(‘DB_TBL_PREFIX’,‘WROX_’);
//establish a connection to the database server
if(!$GLOBALS[‘DB’]=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD))
{
die(‘Error:Unable to connect to database server .’);
}
if(!mysql_select_db(DB_SCHEMA, $GLOBALS [‘DB’]))
{
mysql_close($GLOBALS [‘DB’]);
die (‘Error :unable to select database schema.’);
}
?>


  1. A-Z0-9 ↩︎

The following article may help you to learn some debugging techniques.

Effortless (or Better!) Bug Detection with PHP Assertions