ciao,
ho questa classe che riceve dal form i dati per una registrazione utente.
mi funziona tutto: gestione errori, invio email per conferma registrazione, ma non fa la cosa più importante...non inserisce nulla all'interno del DB e non mi restituisce nessun tipo di warning o errore....
perchè????
la classe:
Codice PHP:
<?php ini_set('display_errors', 'On');
error_reporting(E_ALL);
class NewUser {
public $conn;
public function AddUser()
{
$this->ErrorReport();
}
protected function DbConnect()
{
include "db_conn.php";
$this->conn = mysql_connect($host,$user,$password) OR die("Impossibile connettersi al database");
mysql_select_db($db, $this->conn);
}
protected function IsEmptyField()
{
if(empty($_POST['nome']) OR empty($_POST['email']) OR empty($_POST['password']) OR empty($_POST['provincia']))
{ return TRUE;
} else {
return FALSE;
}
}
protected function VerifyPassword()
{ if($_POST['password'] == $_POST['password2'])
{ return TRUE;
} else {
return FALSE;
}
}
protected function UsernameExists()
{ $this->DbConnect();
$sql = "SELECT nome FROM tbl_user_reg WHERE nome='$_POST[nome]'";
$res = mysql_query($sql, $this->conn);
if($row = mysql_fetch_array($res))
{
mysql_close($this->conn);
return TRUE;
} else {
mysql_close($this->conn);
return FALSE;
}
}
protected function EmailExists()
{ $this->DbConnect();
$sql = "SELECT * FROM tbl_user_reg WHERE email='$_POST[email]'";
$res = mysql_query($sql, $this->conn);
if($row = mysql_fetch_array($res))
{
mysql_close($this->conn); return TRUE;
} else
{ mysql_close($this->conn);
return FALSE;
}
}
protected function VerifyEmail()
{ $pattern = "^([a-zA-Z0-9])+([a-zA-Z0-9]+[-_\.]?)*([a-zA-Z0-9])+(@)([a-zA-Z0-9])+([a-zA-Z0-9]+[-_\.]?)*([a-zA-Z0-9])+(\.[a-z]{2,4})$";
if(ereg($pattern,$_POST['email'])) {
return TRUE;
} else {
return FALSE;
}
}
public function ErrorResult($num)
{
header("Location: modulo_iscrizione_newsletter.php?alert=" . $num); die;
}
protected function ErrorReport()
{
if($this->IsEmptyField())
{
$this->ErrorResult(1);
}
if(!$this->VerifyPassword())
{
$this->ErrorResult(2);
}
if($this->UsernameExists())
{
$this->ErrorResult(3);
}
if($this->EmailExists())
{
$this->ErrorResult(4);
}
if(!$this->VerifyEmail())
{
$this->ErrorResult(5);
}
$this->InsertNewUser();
}
protected function GetKey() { $car = "aAbBcCdDeEfFgGhHiIlLjJkKmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789"; $dim = 40; srand((double)microtime()*1000000); $string = '' ;
for($inc=0; $inc<$dim; $inc++)
{
$rand = rand(0, strlen($car)-1);
$scar = substr($car, $rand, 1);
$string = $string . $scar;
} return $string;
}
protected function SendUserMail($key)
{ $content = "Benvenuto $_POST[nome],\r\n"; $content .= "per confermare la tua iscrizione devi cliccare sul seguente link:\r\n\r\n"; $content .= "http://localhost/newsletter/verify_user.php?key=" . $key;
mail($_POST['email'], "Iscrizione al sito...", $content, "From: io<nome@miamail.it>");
return;
}
protected function InsertNewUser()
{
$password = md5($_POST['password']);
$key_control = $this->GetKey();
$sql = "INSERT INTO tbl_user_reg (nome,email,password,provincia,key_control) VALUES ('$_POST[nome]','$_POST[email]','$password','$_POST[provincia]','$key_control')";
$this->DbConnect();
mysql_query($sql,$this->conn);
mysql_close($this->conn);
$this->SendUserMail($key_control);
}
public function VerifyUser()
{
$sql = "SELECT id_user_reg FROM tbl_user_reg WHERE key_control='$_GET[key]'"; $this->DbConnect();
$res = mysql_query($sql,$this->conn);
if($row = mysql_fetch_array($res))
{
$query = "UPDATE tbl_user_reg SET ver=1,key_control='0' WHERE id='$row[id]'"; mysql_query($query,$this->conn);
mysql_close($this->conn);
echo "Il tuo account è ora attivato!";
} else {
echo "Impossibile verificare l'account!";
}
}
}
?>