From 804d7ce98b6d8a15b26047936e47fcdb1f3bd85f Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sun, 5 Feb 2017 22:11:00 +0100 Subject: [PATCH] restructuring --- db.php | 3 ++- functions.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ index.php | 5 +++-- login.php | 27 ------------------------ login_failed.php | 16 ++++++++++++++ navigation.php | 6 ++---- 6 files changed, 78 insertions(+), 34 deletions(-) create mode 100644 functions.php delete mode 100644 login.php create mode 100644 login_failed.php diff --git a/db.php b/db.php index 0ae7c44..5cafb30 100644 --- a/db.php +++ b/db.php @@ -6,7 +6,8 @@ $db_password = 'password'; $db = 'webshopdb'; $db_port = '3306'; -$con = mysqli_connect("$db_server","$db_user","$db_password","$db","$db_port"); +$db_connection = mysqli_connect("$db_server","$db_user","$db_password", + "$db","$db_port"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..f9147d5 --- /dev/null +++ b/functions.php @@ -0,0 +1,55 @@ + +

Username/password is incorrect.

+
Click here to Login"; + } + } +} +// If form submitted, insert values into the database. +function register() +{ + if (isset($_REQUEST['username'])) { + // removes backslashes + $username = stripslashes($_REQUEST['username']); + //escapes special characters in a string + $username = mysqli_real_escape_string($db_connection,$username); + $email = stripslashes($_REQUEST['email']); + $email = mysqli_real_escape_string($db_connection,$email); + $password = stripslashes($_REQUEST['password']); + $password = mysqli_real_escape_string($db_connection,$password); + $trn_date = date("Y-m-d H:i:s"); + $query = "INSERT into `users` (username, password, email, trn_date) + VALUES ('$username', '".md5($password)."', + '$email', '$trn_date')"; + $result = mysqli_query($db_connection,$query); + if ($result) { + echo "
+

You are registered successfully.

+
Click here to Login
"; + } +} +} +?> diff --git a/index.php b/index.php index 83b8e5b..f745aa5 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,6 @@ @@ -23,7 +24,7 @@ include 'login.php';
- +

Not registered yet? Register Here

diff --git a/login.php b/login.php deleted file mode 100644 index b7b742f..0000000 --- a/login.php +++ /dev/null @@ -1,27 +0,0 @@ - -

Username/password is incorrect.

-
Click here to Login"; - } -} -?> diff --git a/login_failed.php b/login_failed.php new file mode 100644 index 0000000..c5bacb5 --- /dev/null +++ b/login_failed.php @@ -0,0 +1,16 @@ + + + + + + + + + + + + + +

Login failed!

+ + diff --git a/navigation.php b/navigation.php index 0b36c46..8a0921f 100644 --- a/navigation.php +++ b/navigation.php @@ -1,7 +1,5 @@ - +' -?> +