-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearnphp.php
More file actions
88 lines (64 loc) · 1.9 KB
/
learnphp.php
File metadata and controls
88 lines (64 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<html>
<head>
<title>Information Gathered</title>
</head>
<body>
<?php
echo "<p>Data processed</p>";
$email = $_POST['email'];
$password = $_POST['password'];
$conn = new mysqli("localhost", "root", "");
if($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "CREATE DATABASE IF NOT EXISTS mydb";
if($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
$link = mysqli_connect("localhost", "root", "", "mydb");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "CREATE TABLE IF NOT EXISTS UserList(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(70) NOT NULL UNIQUE,
password VARCHAR(30) NOT NULL,
num_credits INT NOT NULL
)";
if(mysqli_query($link, $sql)){
echo "Table created successfully";
} else{
echo "ERROR: Not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
$conn = mysqli_connect("localhost", "root", "", "mydb");
if(!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO UserList (email, password)
VALUES ('$email', '$password')";
if($conn->query($sql)===TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
mysqli_close($conn);
/*
// $hash is what you would store in your database
$hash = password_hash($password, PASSWORD_DEFAULT, ['cost' => 12]);
// $hash would be the $hash (above) stored in your database for this user
$checked = password_verify($password, $hash);
if ($checked) {
echo 'password correct</br>';
} else {
echo 'wrong credentials</br>';
}
*/
echo "email: " . $email . "</br>";
echo "password: " . $password . "</br>";
?>
</body>
</html>