Guest User

Untitled

a guest
Oct 25th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.36 KB | None | 0 0
  1. <?php
  2.  
  3. include('header.php');
  4.  
  5. if(!isset($_SESSION))
  6. {
  7. session_start();
  8. }
  9.  
  10. require_once("user.php");
  11.  
  12.  
  13.  
  14. $user = new User();
  15. //Remember to give your form's submit tag a name ="submit " attribute
  16.  
  17.  
  18. if(isset($_POST['register'])){
  19.  
  20. $user->customer=trim($_POST['c_name']);
  21. $user->email=trim($_POST['c_email']);
  22. $user->password=trim($_POST['c_pass']);
  23. $user->contact=trim($_POST['c_contact']);
  24. $user->address=trim($_POST['c_address']);
  25. $user->about=trim($_POST['about']);
  26. $user->gender=trim($_POST['gender']);
  27.  
  28.  
  29. $user->create();
  30. }
  31.  
  32.  
  33. ?>
  34.  
  35. <!DOCTYPE html>
  36. <html>
  37. <head>
  38. <title>Register</title>
  39. <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
  40. <script type="text/javascript" src ="assets/js/bootstrap.min.js"></script>
  41. </head>
  42. <body>
  43.  
  44. <div class="container">
  45.  
  46.  
  47.  
  48. <div class="col-md-9">
  49. <div class="box">
  50.  
  51. <center>
  52. <h2>
  53. Register A new Account
  54. </h2>
  55. <p class="text-muted">
  56. If you any question please fell to contact us
  57. </p>
  58.  
  59. </center>
  60.  
  61. <form action="registration.php" method="post" >
  62. <div class="form-group">
  63. <label>
  64. Customer Name
  65. </label>
  66. <input type="text" class ="form-control" name="c_name" required>
  67.  
  68. </div>
  69. <div class="form-group">
  70. <label>
  71. Customer Email
  72. </label>
  73. <input type="email" class ="form-control" name="c_email" required>
  74.  
  75. </div>
  76.  
  77. <div class="form-group">
  78. <label>
  79. Customer Password
  80. </label>
  81. <input type="password" class ="form-control" name="c_pass" required>
  82.  
  83. </div>
  84.  
  85.  
  86.  
  87. <div class="form-group">
  88. <label>
  89. Customer Contact
  90. </label>
  91. <input type="text" class ="form-control" name="c_contact" required>
  92.  
  93. </div>
  94.  
  95. <div class="form-group">
  96. <label>
  97. Customer Address
  98. </label>
  99. <input type="text" class ="form-control" name="c_address" required>
  100.  
  101. </div>
  102.  
  103. <div class="form-group" >
  104. <label>
  105. About you
  106. </label>
  107. <textarea class="form-control" name="about"></textarea>
  108. </div>
  109.  
  110. <div class="form-group">
  111. <label >
  112. Gender:
  113. </label>
  114. <br/>
  115. <label class="radio" >
  116. <input type="radio" name="gender" value="male">Male
  117. </label>
  118. <label class="radio" >
  119. <input type="radio" name="gender" value="female">Female
  120. </label>
  121.  
  122.  
  123.  
  124. </div>
  125.  
  126. <div class="text-center">
  127. <button type="submit" name="register" class="btn btn-primary"><i class="fa fa-customer-md"></i>Register</button>
  128. </div>
  129.  
  130. </form>
  131. </div>
  132. </div>
  133.  
  134.  
  135. </div>
  136. </body>
  137. </html>
  138.  
  139. <?php
  140. //if it is going to need the database , then it's
  141. //probaly smart to require it before we start
  142. require_once('database.php');
  143.  
  144. class User{
  145. public $customer='';
  146. public $email='';
  147. public $password='';
  148. public $contact='';
  149. public $address='';
  150. public $about='';
  151. public $gender='';
  152.  
  153.  
  154.  
  155. public static function authenticate($username="",$password=""){
  156. global $database;
  157. $username =$database->escape_value($username);
  158. $password = $database->escape_value($password);
  159. $sql ="SELECT * FROM user WHERE email ='{$username}' AND password ='{$password}' LIMIT 1";
  160. $result_array = self::find_by_sql($sql);
  161. return !empty($result_array)? array_shift($result_array):false;
  162. }
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. public static function find_by_sql($sql = ""){
  171. global $database;
  172. $result_set = $database->query($sql);
  173. $object_array = array();
  174. while($row = $database->fetch_array($result_set)){
  175.  
  176. $object_array[] = self::instantiate($row);
  177.  
  178. }
  179. return $object_array;
  180. }
  181.  
  182.  
  183. private static function instantiate($record){
  184. $object = new self;
  185.  
  186. foreach ($record as $attribute => $value) {
  187.  
  188. if($object->has_attribute($attribute)){
  189. $object->$attribute = $value;
  190.  
  191. }
  192. }
  193. return $object;
  194. }
  195.  
  196.  
  197. private function has_attribute($attribute){
  198. //get_object_vars returns an associative array with all attributes
  199. //(incl.privae one) as the keys and their current values as the
  200. $object_vars = $this->attributes();
  201. //we dont care about the value,we just want to know if the key exists
  202. //will return true or false
  203. return array_key_exists($attribute, $object_vars);
  204. }
  205. protected function attributes(){
  206. //return an array of attribute names and theri values
  207. foreach (self::$db_fields as $field) {
  208. if(property_exists($this,$field)){
  209. $attributes[$field] =$this->$field;
  210. }
  211. }
  212. return $attributes;
  213. }
  214.  
  215.  
  216.  
  217.  
  218. public function create(){
  219. global $database;
  220. $sql = "INSERT INTO customer (customer,email,password,contact,address,about,gender) VAlUES('$customer','$email','$password','$contact','$address','$about','$gender')";
  221. echo $address .' fdg adfdfhfdkja';
  222.  
  223. $database->query($sql);
  224.  
  225.  
  226.  
  227. }
  228.  
  229.  
  230. }
  231.  
  232.  
  233. ?>
  234.  
  235. <?php error_reporting(E_ALL);//display all the error of this page
  236. ?>
  237. <?php
  238. require_once("config/config.php");
  239. class MySQLDatabase{
  240. private $connection;
  241. public $last_query;
  242. private $magic_quotes_active;
  243. private $real_escape_string_exists;
  244. function __construct(){
  245. $this->open_connection();
  246. $this->magic_quotes_active = get_magic_quotes_gpc();
  247. $this->real_escape_string_exists = function_exists("mysql_real_escape_string");
  248. //i.e. PHP >=v4.3.0 or higher
  249. }
  250.  
  251. function open_connection(){
  252.  
  253. //CREATE A DATABASE CONNECTION
  254. $this->connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
  255. if(!$this->connection){
  256. die("database connecton failed ");
  257. }else {
  258. //Select the database
  259. $db_select = mysqli_select_db($this->connection,DB_NAME);
  260.  
  261.  
  262. if(!$db_select){
  263. die("Database selection failed: ".mysqli_error());
  264. }
  265. }
  266. }
  267.  
  268. public function close_connection(){
  269. if(isset($this->connection)){
  270. mysqli_close($this->connection);
  271. unset($this->connection);
  272. }
  273. }
  274.  
  275. public function query($sql){
  276. $this->last_query = $sql;
  277. $result = mysqli_query($this->connection,$sql);
  278. $this->confirm_query($result);
  279. return $result;
  280.  
  281. }
  282.  
  283. private function confirm_query($result){
  284. if(!$result)
  285. {
  286. $output = "Database query failed :" .mysqli_connect_error() . "<br>";
  287. $output .= "Last SQL query is: " . $this->last_query;
  288. die ($output);
  289. }
  290. }
  291.  
  292.  
  293. public function escape_value($value){
  294.  
  295. if($this->real_escape_string_exists){
  296. //undo any magic quote effects so mysql_real_escape_string can do the work
  297.  
  298. if($this->magic_quotes_active){
  299. $value = stripslashes($value);}
  300.  
  301. $value = mysql_real_escape_string($value);
  302. }
  303. else {
  304. //magic quotes arent already on the add slashes manually
  305. if(!$this->magic_quotes_active){
  306. $value = addslashes($value);
  307. }
  308. //if magic quotes are active,then the slashes already exist
  309. }
  310. return $value;
  311. }
  312.  
  313. public function fetch_array($result_set){
  314. return mysqli_fetch_array($result_set);
  315. }
  316.  
  317. public function num_rows($result_set){
  318. return mysqli_num_rows($result_set);
  319. }
  320. public function insert_id(){
  321. //get the last id inserted over the current db connection
  322. return mysqli_insert_id($this->connection);
  323. }
  324.  
  325. public function affected_rows(){
  326. return mysqli_affected_rows($this->connection);
  327. }
  328. }
  329.  
  330. $database = new MySQLDatabase();
  331.  
  332.  
  333. ?>
Add Comment
Please, Sign In to add comment