add code from login in php (not finished yet)
This commit is contained in:
@@ -12,7 +12,8 @@ Wichtige Informationen
|
|||||||
- JavaScript - [./javascript](/Zweites%20Jahr/javascript/)
|
- JavaScript - [./javascript](/Zweites%20Jahr/javascript/)
|
||||||
- Unterrichts Projekt - [./unterrichts_projekt](/Zweites%20Jahr/unterrichts_projekt/portal/register.php) (Register Seite)
|
- Unterrichts Projekt - [./unterrichts_projekt](/Zweites%20Jahr/unterrichts_projekt/portal/register.php) (Register Seite)
|
||||||
|
|
||||||
## 29-04-26 - JS
|
## 29-04-26 - JS + PHP
|
||||||
|
- Login in PHP (unfertig)
|
||||||
- Einstieg in JAVASCRIPT
|
- Einstieg in JAVASCRIPT
|
||||||
|
|
||||||
## 27-03-26 - PHP (Unterrichts Projekt)
|
## 27-03-26 - PHP (Unterrichts Projekt)
|
||||||
|
|||||||
@@ -15,6 +15,17 @@ function db_connect(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function init_db() {
|
||||||
|
$dbh = db_connect();
|
||||||
|
$sql = "CREATE TABLE user (
|
||||||
|
u_id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
u_email VARCHAR(100) NOT NULL UNIQUE,
|
||||||
|
u_pw VARCHAR(100) NOT NULL
|
||||||
|
)";
|
||||||
|
|
||||||
|
|
||||||
|
$dbh->exec($sql);
|
||||||
|
}
|
||||||
|
|
||||||
// Test:
|
// Test:
|
||||||
// db_connect();
|
// db_connect();
|
||||||
13
Zweites Jahr/unterrichts_projekt/inc/db_run_init.php
Normal file
13
Zweites Jahr/unterrichts_projekt/inc/db_run_init.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
<h1> Init DB</h1>
|
||||||
|
|
||||||
|
<h2> Tables </h2>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "db_connection_function.php";
|
||||||
|
|
||||||
|
|
||||||
|
init_db();
|
||||||
|
|
||||||
|
echo "finished. DB initialized!";
|
||||||
68
Zweites Jahr/unterrichts_projekt/portal/login.php
Executable file
68
Zweites Jahr/unterrichts_projekt/portal/login.php
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Anmelden</h2>
|
||||||
|
<form>
|
||||||
|
<label>E-Mail: <input name = "email" type="email" ></label><br>
|
||||||
|
<label>Passwort: <input name = "pw" type="password"></label><br>
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once "../inc/db_connection_function.php";
|
||||||
|
//DB-Verbindung aufbauen----------------------------------------------------
|
||||||
|
$dbh = db_connect();
|
||||||
|
|
||||||
|
|
||||||
|
if(!empty($_REQUEST))
|
||||||
|
{
|
||||||
|
if($_REQUEST['email'] != "" AND $_REQUEST['pw'] != "")
|
||||||
|
{
|
||||||
|
$email = $dbh -> quote($_REQUEST['email']);
|
||||||
|
$pw = $dbh -> quote($_REQUEST['pw']);
|
||||||
|
|
||||||
|
//DB-Befehl erstellen-------------------------------------------------------
|
||||||
|
$query = " SELECT * FROM user
|
||||||
|
WHERE u_email = $email
|
||||||
|
AND u_pw = $pw";
|
||||||
|
//DB-Befehl ausführen-------------------------------------------------------
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$res = $dbh -> query($query) -> fetch();
|
||||||
|
if($res)
|
||||||
|
{
|
||||||
|
|
||||||
|
$_SESSION['loggedin'] = $email;
|
||||||
|
echo "<p>Angemeldet als $_SESSION[loggedin]!</p>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "<p>Benutzer nicht registriert oder Anmeldedaten falsch!</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(PDOException $e)
|
||||||
|
{
|
||||||
|
echo "<p>Ooops, da ist was schief gelaufen!<br>";
|
||||||
|
die("Versuchen Sie es später noch einmal!</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "<p>Beide Felder müssen ausgefüllt werden!</p>";
|
||||||
|
}
|
||||||
|
// Ende Felder alle ausgefüllt?
|
||||||
|
|
||||||
|
} //Ende Submit gedrückt?
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user