Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #############################
- ############################# Connection To Database Info for Sign up ################
- public function signup($user_name,$user_pass,$validation){
- $valid = new database();
- $valid->connect("validation");
- $query = "SELECT code FROM validation WHERE id='1'";
- $result = $valid->myQuery($query);
- $parts = $result->fetch_assoc();
- $code = $parts['code'];
- $valid->disconnect();
- if($code == $validation){
- $this->user = new database();
- $link = $this->user;
- $link->connect("user");
- $link->myQuery($query);
- $query = "INSERT INTO ".$link->table_used." (user_name, user_pass) VALUES ('".$user_name."','".$user_pass."')";
- $link->myQuery($query);
- if($link->success){
- $_SESSION['loggedin'] = TRUE;
- $_SESSION['user'] = $user_name;
- $_SESSION['enc'] = $user_pass;
- $link->disconnect();
- return TRUE;
- header('location:../admin/admin_controlp.php');
- }else {
- $link->disconnect();
- return FALSE;
- }
- }else{
- header('location:../admin/adminlogin.php?signup=failed');
- }
- }
- #############################
- ############################# DATABASE CLASS ###########################
- <?php
- /* Purpose: To act as a class for intereacting with a MYSQL database */
- class database {
- /*Default properties for database connection information*/
- private $db_user = "aaron";
- private $db_pass = "test";
- private $db_host = "127.0.0.1";
- public $db_used = "instert_db";
- /* Set your tables to be used */
- public $table_used ="used_table";
- /*Stores the connection to the database*/
- private $con;
- public $success = "";
- public $num_rows;
- /* dbs() : Selects a data base to use based on what
- * the Programmer puts in for a variable in connect($db)[below]
- * which is then passed to dbs($select_db) and put into the switch statement
- * to 'SET' what the information used to connect to the database.
- */
- public function dbs($select_db){
- switch($select_db){
- case "user": {
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "login";
- }
- break;
- case "main":{
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "main_info";
- }
- break;
- case "news":{
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "news_post";
- }
- break;
- case "astrology":{
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "astrology_info";
- }
- break;
- case "services":{
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "services_info";
- }
- break;
- case "about":{
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "about_info";
- }
- break;
- case "contact":{
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "contact_info";
- }
- break;
- case "validation":{
- $this->db_user = "aaron";
- $this->db_pass = "test";
- $this->db_host = "127.0.0.1";
- $this->db_used = "zodiac_admin";
- $this->table_used = "validation";
- }
- default:{
- echo "Invalid Database Selection.";
- }
- }
- }
- /* connect() : calls dbs() and which sets the the variables to be
- * used to connect to a database. This method also sets the $con variable
- * by making a mysqli() connection useing the variables set by dbs()
- */
- public function connect($db) {
- $this->dbs($db);
- $this->con = new mysqli($this->db_host,$this->db_user,$this->db_pass,$this->db_used);
- }
- /* disconnect() : closes the connection to the database. */
- public function disconnect(){
- $this->con->close();
- }
- /* myQuery() : Sends the query to the database. Sets the success variable to true if
- * the query succeded.*/
- public function myQuery($query){
- $result = $this->con->query($query);
- if($result){
- $this->success = TRUE;
- }else $this->sucess = FALSE;
- $this->num_rows = $result->num_rows;
- return $result;
- }
- public function mysqlErr(){
- $result = mysql_error($this->con);
- return $result;
- }
- /* injSecOne() : acts as a security measure to prevent MySQL Injection attacks */
- public function injSecOne($input){
- $safe_input = mysqli_real_escape_string($this->con,$input);
- return $safe_input;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement