Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.12 KB | None | 0 0
  1. <?PHP
  2.     Class MySQL
  3.     {
  4.         // Connection of the mysql api
  5.         Private $Connection ;
  6.  
  7.         // Database information
  8.         Private $Hostname ;
  9.         Private $Username ;
  10.         Private $Password ;
  11.         Private $Database ;
  12.  
  13.         // Last handles of query and row
  14.         Private $HandleOfLastQuery ;
  15.         Private $HandleOfLastRow ;
  16.  
  17.         // Methods to set and get the hostname
  18.         Public Function GetHostname ( )
  19.         {
  20.             Return $this->Hostname ;
  21.         }
  22.         Public Function SetHostname ( $Hostname )
  23.         {
  24.             $this->Hostname = $Hostname ;
  25.         }
  26.  
  27.         // Methods to set and get the username
  28.         Public Function GetUsername ( )
  29.         {
  30.             Return $this->Username ;
  31.         }
  32.         Public Function SetUsername ( $Username )
  33.         {
  34.             $this->Username = $Username ;
  35.         }
  36.  
  37.         // Methods to set and get the password
  38.         Public Function GetPassword ( )
  39.         {
  40.             Return $this->Password ;
  41.         }
  42.         Public Function SetPassword ( $Password )
  43.         {
  44.             $this->Password = $Password ;
  45.         }
  46.  
  47.         // Methods to set and get the database
  48.         Public Function GetDatabase ( )
  49.         {
  50.             Return $this->Database ;
  51.         }
  52.         Public Function SetDatabase ( $Database )
  53.         {
  54.             $this->Database = $Database ;
  55.         }
  56.  
  57.         // Method to initialize and connect to the
  58.         // mysql server and database
  59.         Public Function Initialize ( )
  60.         {
  61.             $this->Connection = MySQL_Connect ( $this->Hostname , $this->Username , $this->Password ) ;
  62.             MySQL_Select_DB ( $this->Database , $this->Connection ) ;
  63.         }
  64.  
  65.         // Method to finalize and close the
  66.         // mysql server and database connection
  67.         Public Function Finalize ( )
  68.         {
  69.             MySQL_Close ( $this->Connection ) ;
  70.         }
  71.  
  72.         // Method to send a query to the
  73.         // mysql server and database
  74.         Public Function Query ( $Query )
  75.         {
  76.             $this->HandleOfLastQuery = MySQL_Query ( $Query , $this->Connection ) ;
  77.         }
  78.  
  79.         // Method to fetch an object
  80.         Public Function Fetch ( )
  81.         {
  82.             $this->HandleOfLastRow = MySQL_Fetch_Object ( $this->HandleOfLastQuery ) ;
  83.             Return $this->HandleOfLastRow ;
  84.         }
  85.  
  86.         // Method to get the row
  87.         Public Function GetRow ( )
  88.         {
  89.             Return $this->HandleOfLastRow ;
  90.         }
  91.  
  92.         // Method to get the number of rows
  93.         Public Function GetNumberOfRows ( )
  94.         {
  95.             Return MySQL_Num_Rows ( $this->HandleOfLastQuery ) ;
  96.         }
  97.     } ;
  98.  
  99.     $MySQL = new MySQL ;
  100.         $MySQL->SetHostname ( "xx" ) ;
  101.         $MySQL->SetUsername ( "xx" ) ;
  102.         $MySQL->SetDatabase ( "xx" ) ;
  103.         $MySQL->SetPassword ( "xx" ) ;
  104.            
  105.  
  106.     $pw1 = $_POST["pw"];
  107.     $pw = md5($pw1);
  108.     $user = $_POST["user"];
  109. if((($pw1 == "") and ($user == "")) or (($user == "Ihr Benutzername") and ($pw1 == "Ihr Kennwort")))
  110. {
  111. echo "Bitte das Formular ausfüllen";
  112. }
  113. else
  114. {
  115. $MySQL->Initialize ( ) ;
  116. $result = $MySQL->Query ( "SELECT id FROM cms_login WHERE benutzer LIKE '$user'" );
  117. $MySQL->Fetch ( ) ;
  118. $MySQL->Finalize ( ) ;
  119. if($result == 0)
  120.     {
  121.         $MySQL->Initialize ( ) ;
  122.         $eintragen = $MySQL->Query ( "INSERT INTO cms_login (benutzer, passwort) VALUES ('$user', '$pw')" );
  123.         $MySQL->Fetch ( ) ;
  124.         $MySQL->Finalize ( ) ;
  125.             if($eintragen == true)
  126.             {
  127.                 echo "Benutzername <b>$user</b> wurde erstellt.";
  128.             } else {
  129.                 echo "Fehler beim Speichern des Benutzernamens.";
  130.             }
  131.     } else {
  132.         echo "Benutzername schon vorhanden!";
  133.     }
  134. }
  135. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement