Logica y conexion con la base de datos hecha

This commit is contained in:
2021-05-20 22:08:31 -03:00
parent 9b934b2c95
commit 9b8a533548
7 changed files with 75 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
require 'messages.php';
require 'sanitize.php';
require './sql/querys.php';
$user = $_POST['user'];
$password = $_POST['password'];
@@ -14,7 +15,19 @@ if (isset($_POST['submit'])) {
if(strlen($password) <= 20){
sanitize('user', $user);
$c = verifyDB($user, $password);
if ($c[0][1] === $user && $c[0][2] === $password) {
echo '<script>
window.location.replace(`../success-pages/loginS.html`)
</script>';
} else {
echo error('The User or the Password are wrong. Please try again');
echo backToPreviusPage(4, '../login.html');
}
} else {
echo error('The password has more characters than allowed!');

View File

@@ -2,6 +2,7 @@
require 'messages.php';
require 'sanitize.php';
require './sql/querys.php';
$user = $_POST['user'];
$password = $_POST['password'];
@@ -17,7 +18,11 @@ if (isset($_POST['submit'])) {
if (strlen($password) <= 20) {
sanitize('user', $user);
addToDB(sanitize('user', $user), $password);
echo '<script>
window.location.replace(`../success-pages/registerS.html`)
</script>';
} else {
echo error('The password has more characters than allowed!');

9
logic/sql/connection.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
try {
$connect = new PDO('mysql:host=localhost;dbname=formulariologin1', 'root', '');
} catch(PDOexception $e) {
echo "Error: " . $e -> getMessage();
}
?>

30
logic/sql/querys.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
function addToDB($user, $password) {
require './sql/connection.php';
$add = $connect -> prepare('insert into users (user, pass) values (?, ?)');
echo 'paso 1';
$add -> bindParam(1, $user, PDO::PARAM_STR);
echo 'paso 2';
$add -> bindParam(2, $password, PDO::PARAM_STR);
echo 'paso 3';
$add -> execute();
echo 'paso 4';
}
function verifyDB($user, $password) {
require './sql/connection.php';
$verify = $connect -> prepare('select * from users where (user, pass) = (?, ?)');
echo 'paso 1';
$verify -> bindParam(1, $user, PDO::PARAM_STR);
echo 'paso 2';
$verify -> bindParam(2, $password, PDO::PARAM_STR);
echo 'paso 3';
$verify -> execute();
echo 'paso 4';
return $verify -> fetchAll();
}
?>

View File

@@ -85,6 +85,20 @@ input:focus {
width: 421px !important;
background-color: rgb(175, 166, 150);
border: 1px rgb(114, 100, 96) solid;
transition:background-color ease-in-out 0.3s;
-webkit-transition:background-color ease-in-out 0.3s;
-moz-transition:background-color ease-in-out 0.3s;
-ms-transition:background-color ease-in-out 0.3s;
-o-transition:background-color ease-in-out 0.3s;
}
.submit:hover {
background-color: rgb(233, 221, 201);
transition:background-color ease-in-out 0.3s;
-webkit-transition:background-color ease-in-out 0.3s;
-moz-transition:background-color ease-in-out 0.3s;
-ms-transition:background-color ease-in-out 0.3s;
-o-transition:background-color ease-in-out 0.3s;
}

View File

@@ -0,0 +1 @@
<h1>mfasddfmsadofasdmfpadsofma</h1>

View File

@@ -0,0 +1 @@
<h1>asdojfnadsjfnasfnadsjfda</h1>