Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. #############################
  2. ############################# Connection To Database Info for Sign up ################
  3. public function signup($user_name,$user_pass,$validation){
  4.  
  5. $valid = new database();
  6.  
  7. $valid->connect("validation");
  8.  
  9. $query = "SELECT code FROM validation WHERE id='1'";
  10.  
  11. $result = $valid->myQuery($query);
  12.  
  13. $parts = $result->fetch_assoc();
  14.  
  15. $code = $parts['code'];
  16.  
  17. $valid->disconnect();
  18.  
  19. if($code == $validation){
  20. $this->user = new database();
  21.  
  22. $link = $this->user;
  23.  
  24. $link->connect("user");
  25.  
  26. $link->myQuery($query);
  27.  
  28. $query = "INSERT INTO ".$link->table_used." (user_name, user_pass) VALUES ('".$user_name."','".$user_pass."')";
  29.  
  30. $link->myQuery($query);
  31.  
  32. if($link->success){
  33. $_SESSION['loggedin'] = TRUE;
  34. $_SESSION['user'] = $user_name;
  35. $_SESSION['enc'] = $user_pass;
  36. $link->disconnect();
  37. return TRUE;
  38. header('location:../admin/admin_controlp.php');
  39. }else {
  40. $link->disconnect();
  41. return FALSE;
  42. }
  43. }else{
  44. header('location:../admin/adminlogin.php?signup=failed');
  45.  
  46. }
  47.  
  48. }
  49.  
  50. #############################
  51. ############################# DATABASE CLASS ###########################
  52.  
  53. <?php
  54. /* Purpose: To act as a class for intereacting with a MYSQL database */
  55.  
  56. class database {
  57.  
  58. /*Default properties for database connection information*/
  59. private $db_user = "aaron";
  60. private $db_pass = "test";
  61. private $db_host = "127.0.0.1";
  62. public $db_used = "instert_db";
  63.  
  64. /* Set your tables to be used */
  65. public $table_used ="used_table";
  66.  
  67. /*Stores the connection to the database*/
  68. private $con;
  69.  
  70. public $success = "";
  71.  
  72. public $num_rows;
  73.  
  74. /* dbs() : Selects a data base to use based on what
  75. * the Programmer puts in for a variable in connect($db)[below]
  76. * which is then passed to dbs($select_db) and put into the switch statement
  77. * to 'SET' what the information used to connect to the database.
  78. */
  79. public function dbs($select_db){
  80.  
  81. switch($select_db){
  82. case "user": {
  83. $this->db_user = "aaron";
  84. $this->db_pass = "test";
  85. $this->db_host = "127.0.0.1";
  86. $this->db_used = "zodiac_admin";
  87. $this->table_used = "login";
  88. }
  89. break;
  90. case "main":{
  91. $this->db_user = "aaron";
  92. $this->db_pass = "test";
  93. $this->db_host = "127.0.0.1";
  94. $this->db_used = "zodiac_admin";
  95. $this->table_used = "main_info";
  96. }
  97. break;
  98. case "news":{
  99. $this->db_user = "aaron";
  100. $this->db_pass = "test";
  101. $this->db_host = "127.0.0.1";
  102. $this->db_used = "zodiac_admin";
  103. $this->table_used = "news_post";
  104. }
  105. break;
  106. case "astrology":{
  107. $this->db_user = "aaron";
  108. $this->db_pass = "test";
  109. $this->db_host = "127.0.0.1";
  110. $this->db_used = "zodiac_admin";
  111. $this->table_used = "astrology_info";
  112. }
  113. break;
  114. case "services":{
  115. $this->db_user = "aaron";
  116. $this->db_pass = "test";
  117. $this->db_host = "127.0.0.1";
  118. $this->db_used = "zodiac_admin";
  119. $this->table_used = "services_info";
  120. }
  121. break;
  122. case "about":{
  123. $this->db_user = "aaron";
  124. $this->db_pass = "test";
  125. $this->db_host = "127.0.0.1";
  126. $this->db_used = "zodiac_admin";
  127. $this->table_used = "about_info";
  128. }
  129. break;
  130. case "contact":{
  131. $this->db_user = "aaron";
  132. $this->db_pass = "test";
  133. $this->db_host = "127.0.0.1";
  134. $this->db_used = "zodiac_admin";
  135. $this->table_used = "contact_info";
  136. }
  137. break;
  138. case "validation":{
  139. $this->db_user = "aaron";
  140. $this->db_pass = "test";
  141. $this->db_host = "127.0.0.1";
  142. $this->db_used = "zodiac_admin";
  143. $this->table_used = "validation";
  144. }
  145. default:{
  146. echo "Invalid Database Selection.";
  147. }
  148. }
  149. }
  150.  
  151. /* connect() : calls dbs() and which sets the the variables to be
  152. * used to connect to a database. This method also sets the $con variable
  153. * by making a mysqli() connection useing the variables set by dbs()
  154. */
  155. public function connect($db) {
  156. $this->dbs($db);
  157. $this->con = new mysqli($this->db_host,$this->db_user,$this->db_pass,$this->db_used);
  158. }
  159.  
  160. /* disconnect() : closes the connection to the database. */
  161. public function disconnect(){
  162. $this->con->close();
  163. }
  164.  
  165. /* myQuery() : Sends the query to the database. Sets the success variable to true if
  166. * the query succeded.*/
  167. public function myQuery($query){
  168. $result = $this->con->query($query);
  169.  
  170. if($result){
  171. $this->success = TRUE;
  172. }else $this->sucess = FALSE;
  173.  
  174. $this->num_rows = $result->num_rows;
  175.  
  176.  
  177. return $result;
  178. }
  179.  
  180. public function mysqlErr(){
  181. $result = mysql_error($this->con);
  182. return $result;
  183. }
  184.  
  185.  
  186. /* injSecOne() : acts as a security measure to prevent MySQL Injection attacks */
  187. public function injSecOne($input){
  188. $safe_input = mysqli_real_escape_string($this->con,$input);
  189. return $safe_input;
  190. }
  191.  
  192. }
  193.  
  194. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement