· 6 years ago · May 31, 2019, 04:48 PM
1conexión.php
2
3<?php
4
5 $host_db= "localhost";
6 $user_db= "root";
7 $pass_db= "root";
8 $db_name= "tienda";
9?>
10
11
12Registro.html
13
14
15<!DOCTYPE html>
16<html>
17
18<body>
19
20 <h2>The input Element</h2>
21
22 <form action="/df.php" method="POST">
23 Enter your username:
24 <input name="username" type="text">
25 <br><br> Enter your password:
26 <input name="password" type="password">
27 <br><br> Enter your email:
28 <input name="email" type="text">
29 <br><br> Enter your security answer:
30 <input name="respuesta_de_seguridad" type="text">
31 <input type="submit">
32 </form>
33
34</body>
35
36</html>
37
38
39
40df.php
41
42
43<?php
44include ("conexion.php");
45
46$username = $_POST['username'];
47$password = $_POST['password'];
48$email = $_POST['email'];
49$respuesta_de_seguridad = $_POST['respuesta_de_seguridad'];
50
51try {
52 $conn = new PDO("mysql:host=$host_db;dbname=$db_name", $user_db, $pass_db);
53 // set the PDO error mode to exception
54 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
55 $stmt = $conn->prepare('INSERT INTO usuarios (username, password, email, respuesta_de_seguridad) VALUES ( :username, :password, :email, :respuesta_de_seguridad)');
56 $stmt-> bindValue(":username",$username,PDO::PARAM_STR);
57 $stmt-> bindValue(":password",$password,PDO::PARAM_STR);
58 $stmt-> bindValue(":email",$email,PDO::PARAM_STR);
59 $stmt-> bindValue(":respuesta_de_seguridad",$respuesta_de_seguridad,PDO::PARAM_BOOL);
60 $stmt->execute();
61 echo "The user admin has been created with the password admin, now you can log in.";
62 }
63catch(PDOException $e)
64 {
65 echo "You cannot use this query again." . "<br>" . "If you used already this config file, please remove it urgently from the public folder, if not check your database connection data.";
66 }
67?>
68
69
70
71CREATE DATABASE tienda;
72CREATE TABLE IF NOT EXISTS usuarios (
73 id INT NOT NULL AUTO_INCREMENT,
74 username VARCHAR(255) NOT NULL,
75 password VARCHAR(255) NOT NULL,
76 email VARCHAR(255) NOT NULL,
77 respuesta_de_seguridad VARCHAR(255),
78 PRIMARY KEY id(id)
79) ENGINE=INNODB;