-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
106 lines (77 loc) · 2.5 KB
/
Copy pathprocess.php
File metadata and controls
106 lines (77 loc) · 2.5 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
session_start();
/*
$idtoken = $_POST["idtoken"];
$email = $_POST["email"];
echo $email;
*/
$dbhost = 'localhost';
$dbuser = 'root';
$dbpassword = 'G0@tCh33$3M00nC00k!3';
$dbname = 'projectreadinglist';
//table to check
$table_to_query = 'users';
$articledb = 'readingtree';
//login to database; new database instance called db
$db = new mysqli($dbhost, $dbuser, $dbpassword, $dbname);
if($db->connect_errno > 0){
die('Process.php: Unable to connect to database [' . $db->connect_error . ']');
}
//get user info from POST
$idtoken = $_POST["idtoken"];
$email = $_POST["email"];
$query = mysqli_query($db, "SELECT * FROM $table_to_query WHERE email='".$email."'");
if(mysqli_num_rows($query) > 0){
//user already exists
echo "email already exists";
$newemail1 = str_replace("@", "at", $email);
$newemail2 = str_replace(".", "dot", $newemail1);
$_SESSION['idtoken'] = $idtoken;
$_SESSION['rawemail'] = $email;
$_SESSION['filteredemail'] = $newemail2;
//echo "You got this far: process.php";
die;
}else{
//user doesn't yet exist
echo "email does not exist";
//add entry to user table
$saveuser = "INSERT INTO $table_to_query (email) VALUES(?)";
$statement = $db->prepare($saveuser);
//bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('s', $email);
$conn = new mysqli($dbhost, $dbuser, $dbpassword, $articledb);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//create reading list user table
$newemail1 = str_replace("@", "at", $email);
$newemail2 = str_replace(".", "dot", $newemail1);
$sql = "CREATE TABLE `" . $newemail2 ."` (
linkid INT(20) UNSIGNED PRIMARY KEY,
linktitle TEXT NOT NULL,
linkurl TEXT NOT NULL,
linkdate DATE NOT NULL
)";
if ($conn->query($sql) === TRUE) {
echo "Table created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
//start new session for the user
$_SESSION['idtoken'] = $idtoken;
$_SESSION['rawemail'] = $email;
$_SESSION['filteredemail'] = $newemail2;
if($statement->execute()){
print 'Success! ID of last inserted record is : ' .$statement->insert_id .'<br />';
die;
}else{
die('Error : ('. $db->errno .') '. $db->error);
}
$statement->close();
if (!mysqli_query($db,$query))
{
die('Error: ' . mysqli_error($db));
}
}
?>