Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = mysqli_connect('localhost', 'id13157365_ladashboard', 'mAryOXCp/=K4/NqB', 'id13157365_lafilipinadatabase');
- $username = "";
- $name="";
- $location="";
- $errors = array();
- if (isset($_POST['add_btn'])) {
- add_user();
- }
- function add_user(){
- global $db , $errors, $username;
- $username = e($_POST['username']);
- $password_1 = e($_POST['password_1']);
- $password_2 = e($_POST['password_2']);
- if (empty($username)) {
- array_push($errors, "Username is required");
- }
- if (empty($password_1)) {
- array_push($errors, "Password is required");
- }
- if ($password_1 != $password_2) {
- array_push($errors, "The two passwords do not match");
- }
- if (count($errors) == 0) {
- $password = md5($password_1,true);
- if (isset($_POST['user_type'])) {
- $user_type = e($_POST['user_type']);
- $query = "INSERT INTO users (username, password , user)
- VALUES('$username', '$password', '$user_type')";
- mysqli_query($db, $query);
- header('location: renew.php');
- }
- }
- }
- function e($val){
- global $db;
- return mysqli_real_escape_string($db, trim($val));
- }
- if (isset($_POST['login_btn'])) {
- login();
- }
- function login(){
- global $db, $username, $errors;
- $username = e($_POST['username']);
- $password = e($_POST['password']);
- if (count($errors) == 0) {
- $password = md5($password,true);
- $query = "SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1";
- $results = mysqli_query($db, $query);
- if (mysqli_num_rows($results) == 1) {
- $logged_in_user = mysqli_fetch_assoc($results);
- if ($logged_in_user['user'] == 'admin') {
- header('location: AND.html');
- }else{
- header('location: AND.html');
- }
- }else {
- array_push($errors, "Wrong username/password combination");
- }
- }
- }
- if(isset($_POST['searchb'])){
- global $db,$name,$location;
- $searched=$_POST['Searcht'];
- $query_avail1="select * from dummy_names where name='$searched'";
- $result_avail1=mysqli_query($db,$query_avail1);
- if(mysqli_num_rows($result_avail1)==1){
- $available=mysqli_fetch_assoc($result_avail1);
- $name=$available['name'];
- $location=$available['location'];
- }
- }
- if (isset($_POST['ren_btn'])){
- renew();
- }
- function renew(){
- global $db,$errors;
- $name=$_POST['name'];
- $location=$_POST['location'];
- $renewdate=$_POST['rendate'];
- $expdate=$_POST['expdate'];
- $or=$_POST['or'];
- if(empty($name)){
- array_push($errors, "Please Search Name first");
- }
- if(empty($renewdate)){
- array_push($errors, "Please fill up the Renew Date");
- }
- if(empty($renewdate)){
- array_push($errors, "Please fill up the Expiration Date");
- }
- if(empty($or)){
- array_push($errors, "Please fill up the OR#");
- }
- if($renewdate>$expdate){
- array_push($errors, "Please check the expiration date");
- }
- if(count($errors)==0){
- $query = "INSERT INTO renew (name, location , renew_date, expiration_date, OR_num)
- VALUES('$name', '$location', '$renewdate', '$expdate', '$or')";
- mysqli_query($db, $query);
- }
- }
- function display_error() {
- global $errors;
- if (count($errors) > 0){
- echo '<div class="error">';
- foreach ($errors as $error){
- echo $error .'<br>';
- }
- echo '</div>';
- }
- }
Add Comment
Please, Sign In to add comment