[PHP/OOP]Release/Tutorial Registration

01/26/2012 14:05 iKyroja :>#1
Hayho, Elitepvpers.

Ihr schwirren zwar einige Registrations Tutorials etc. herrum, die auf das Standart PHP basieren,
deshalb zeige ich euch heute bzw. stelle ich euch heute eine einfache Registartion zu verfügung
die mit PHP OOP gecodet ist, wer fragen zu dem script hat schreibt sie als kommentar.
ich werde es dan beantworten und wem es nicht gefällt soll ALT+F4 drücken.

register.class.php:
PHP Code:
<?php
define
('SQL_HOST','localhost'); // <- Hier die IP-Adresse der Datenbank eintragen
define('SQL_USER','root');        // <- Hier den Datenbank-User eintagen
define('SQL_PASS','');            // <- Hier das Datenbank Passwort eintragen

$sqlCon mysql_connect(SQL_HOST,SQL_USER,SQL_PASS) or die ('MYSQL CONNECTION FAILED');

class 
Registration {
    private 
$login;
    private 
$password;
    private 
$email;
    private 
$rl_name;
    private 
$social_id;
    private 
$question1;
    private 
$answer1;
    
    public function 
__construct() {
        
$this->login      mysql_real_escape_string($_POST['login']);
        
$this->password  mysql_real_escape_string($_POST['password']);
        
$this->email     mysql_real_escape_string($_POST['email']);
        
$this->rl_name      mysql_real_escape_string($_POST['rl_name']);
        
$this->social_id mysql_real_escape_string($_POST['social_id']);
        
$this->question1 mysql_real_escape_string($_POST['question1']);
        
$this->answer1   mysql_real_escape_string($_POST['answer1']);
    }
    
    public function 
insertsql() {
        
$sqlInsert mysql_query("INSERT INTO
                                  account.account
                                  (login,password,email,real_name,social_id,question1,answer1)
                                  VALUES
                                  ('
$this->login',PASSWORD('$this->password'),'$this->email','$this->rl_name','$this->social_id','$this->question1','$this->answer1')");
        if(
$sqlInsert) {
            return 
true;
        } else {
            return 
false;
        }
                                                                    
    }
    
    public function 
checkUser() {
        
$checkId mysql_num_rows(mysql_query("SELECT login FROM account.account WHERE login = '$this->login'"));
        if(
$checkId  == 0) {
            return 
true;
        } else {
            return 
false;
        }
        
    }
    
    public function 
process() {
        if(!empty(
$this->login) && !empty($this->password) && !empty($this->email) && !empty($this->rl_name) && !empty($this->social_id) && !empty($this->question1) && !empty($this->answer1)) {
            if(
$this->checkUser()) {
                if(
$this->insertsql()) {
                    echo 
'<div id="succes">SUCCES: Du hast erfolgreich den Account <i>"'.$this->login.'"</i> erstellt</div>';
                } else {
                    echo 
'<div id="error">ERROR: FATAL MYSQL ERROR</div> </ br>'.mysql_error();
                }
                
                
            } else {
                echo 
'<div id="error">ERROR: Der Account existiert bereits</div>';
            }
        } else {
            echo 
'<div id="error">ERROR: Es sind nicht alle Felder ausgefüllt</div>';
        }
        
    }
    
}
    
?>
register.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registartion Script</title>
</head>
<style type="text/css">
#error {
    background:#ab7b7b;
    margin:0 auto;
    padding:7px;
    width:550px;
    border:solid 1px #cb0d0d;
    color:#000;
}
#succes {
    background:#a0ab7b;
    margin:0 auto;
    padding:7px;
    width:550px;
    border:solid 1px #9ecb0d;
    color:#000;
}
</style>
<body>
<?php
$question 
= array(
                    
'1'=>'Name deiner Mutter ?',
                    
'2'=>'Name deines Vaters ?',
                    
'2'=>'Name deines Hundes ?'
                  
);
if(isset(
$_POST['submit']) && $_POST['submit'] == 'Anmelden') {
    include_once(
'class/register.class.php');
    
$registration = new Registration;
    
$registration->process();
}
?>
<form action="register.php" method="post">
<table width="500" border="0" align="center" style="margin-top:10px;">
  <tr>
    <td width="147" align="right">AccountID:</td>
    <td width="343"><input type="text" name="login" /></td>
  </tr>
   <tr>
    <td width="147" align="right">Passwort:</td>
    <td width="343"><input type="password" name="password" /></td>
  </tr>
   <tr>
    <td width="147" align="right">Email:</td>
    <td width="343"><input type="text" name="email" /></td>
  </tr>
   <tr>
    <td width="147" align="right">Name:</td>
    <td width="343"><input type="text" name="rl_name" /></td>
  </tr>
   <tr>
    <td width="147" align="right">Löschcode:</td>
    <td width="343"><input type="text" name="social_id" /></td>
  </tr>
   <tr>
    <td width="147" align="right">Sicherheitsfrage:</td>
    <td width="343">
        <select name="question1" style="width:142px;">
            <?php
                
foreach($question as $id => $frage) {
                    echo 
'<option value="'.$id.'">'.$frage.'</option>';
                }
            
?>
        </select>
    </td>
  </tr>
   <tr>
    <td width="147" align="right">Antwort:</td>
    <td width="343"><input type="text" name="answer1" /></td>
  </tr>
   <tr>
    <td colspan="2"><center><input type="submit" name="submit" value="Anmelden" /></center></td>
  </tr>
</table>
</form>

</body>
</html>
! Ich habe es gestet und geschreiben, es funktioniert auch ^^