very new to php. just learn and copy things from youtube.
try to do Registration login. after I uploaded to server and it do nothing, just the table
but no action, not errors show and nothing in my database
hope you guys can help me out..so frustrated!!!!
sean
here is the code:
Reg.php
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
session_start();
if(isset($_POST['register']))
{
include('/class_register.php');
$register = new Register () ;
if($register->process())
echo 'Success!';
else
$register->show_errors();
}
$token = $_SESSION['token'] = md5(uniqid(mt_rand(),true));
?>
<form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'];?> ">
<table width="200" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="61">Username</td>
<td width="123"><input type="text" name="ruser" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="remail"/ ></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="rpass"/ ></td>
</tr>
<tr>
<td><input type="hidden" name="token" value="<?=$token;?>" /></td>
<td><input type="submit" name="Register" value="Sign Up"></td>
</tr>
</table>
</form>
and here is my Class page
<?php
class Register
{
private $username;
private $password;
private $passmd5;
private $email;
private $error;
private $token;
public function _construct ()
{
$this->errors = array();
$this->username = $this->filter($_POST['ruser']);
$this->password = $this->filter($_POST['rpassr']);
$this->token = $_POST['token'];
$this->passmd5 = md5($this->password);
}
public function process ()
{
if($this->valid_token() && $this->valid_data())
$this->register();
return count($this->errors)? 0 : 1;
}
public function filter ($var)
{
return preg_replace('/[^a-zA-Z0-9@.]',' ',$var);
}
public function user_exists()
{
$db_host = "mysql1.**********.com";
$db_username = "a2738497_seanp";
$db_pass = "tang2000";
$db_name = "a2738497_pink";
mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");
$data = mysql_query("SELECT ID FROM users WHERE username = '($this->username)'");
return (mysql_num_rows($data) > 0)? 1:0;
}
public function register ()
{
$db_host = "mysql1.**********.com";
$db_username = "a2738497_seanp";
$db_pass = "tang2000";
$db_name = "a2738497_pink";
mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");
mysql_query("INSERT INTO users (username, password) VALUES ('($this->username)','($this->passmd5)')");
if(mysql_affected_rows() < 1)
$this->errors[] = 'Could not Process Form';
}
public function show_errors ()
{
echo "Errors";
foreach($this->errors as $key=>$value)
echo $value."<br>";
}
public function valid_data ()
{
if($this->user_exists())
$this->errors[] = 'Username Already Taken';
if(empty($this->username))
$this->errors[] = 'Invalid Username';
if(empty($this->password))
$this->errors[] = 'Invalid Passord';
if(empty($this->email) || !eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z] {2,4}) $',$this->email))
$this->errors[] = 'Invalid Email';
return count($this->errors)? 0 : 1;
}
public function valid_token ()
{
if(!isset($_SESSION['token']) || $this->token != $_SESSION['token'])
$this->errors[] = 'Invalid Submission';
return count($this->errors)? 0 : 1;
}
}
?>