trying to connect to the database

master
GhadaA98 2023-05-31 16:03:16 +02:00
parent ed9d1349c0
commit 82d9156636
5 changed files with 98 additions and 89 deletions

View File

@ -51,7 +51,7 @@
<div class="buttonContainer"> <div class="buttonContainer">
<a id="backToHomeButton" href="abmelden_erfolgreich.php">Bestätigen</a> <a id="backToHomeButton" href="abmelden_erfolgreich.php">Bestätigen</a>
<a id="logInAgainButton" href="meinebuecher.html">Abbrechen</a> <a id="logInAgainButton" href="anmelden_meinebuecher.php">Abbrechen</a>
</div> </div>
<br><br><br> <br><br><br>

37
anmeldesystem.php 100644
View File

@ -0,0 +1,37 @@
<?php
session_start();
function register($vorname,
$nachname ,
$strasse,
$hausnummer,
$plz,
$ort,
$email,
$passwort,){
global $db_link;
$vorname = mysqli_real_escape_string($db_link, $vorname);
$nachname = mysqli_real_escape_string($db_link, $nachname);
$email = mysqli_real_escape_string($db_link, $email);
$passwort = md5( $passwort);
$ort = mysqli_real_escape_string($db_link, $ort);
$plz = mysqli_real_escape_string($db_link, $plz);
$strasse = mysqli_real_escape_string($db_link, $strasse);
$hausnummer = mysqli_real_escape_string($db_link, $hausnummer);
$kartenid = 100000000;
$id=1;
//Benutzer schon vorhanden?
$db_res = runSQL("SELECT COUNT(*) FROM benutzer WHERE E-MailAdresse='" . $email . "'");
$row = mysqli_fetch_array($db_res);
if($row['COUNT(*)'] > 0)
{
return 'Es gibt schon einen Benutzer mit der angegebenen E-Mail Adresse';
}
runSQL("INSERT INTO benutzer (VorName, NachName, KartenID, E-MailAdresse,AdressenID, Passwort) VALUES ('". $vorname ."' , '". $nachname ."' ,'". $kartenid ."' , '". $email ."', '". $id ."','". $passwort ."')");
runSQL("INSERT INTO adresse (Stadt, Postleitzahl, Straße, Hausnummer) VALUES ('". $ort ."' , '". $plz ."' ,'". $strasse ."' , '". $hausnummer ."')");
return 'der Benutzer wurde erfolgreich registriert';
}
?>

47
connect.php 100644
View File

@ -0,0 +1,47 @@
<?php
$servername = "localhost";
$username = "web_b-3";
$password = "een7Ao6s";
$dbname = "bibliothek_candle";
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Assume you have a table named 'users' with columns 'name' and 'email'
$vorname = $_POST["vorName"];
$nachname = $_POST['nachName'];
$strasse = $_POST['strasse'];
$hausnummer = $_POST['hausnummer'];
$plz = $_POST['postleitzahl'];
$ort = $_POST['ort'];
$email = $_POST['email'];
$passwort = $_POST['passwort'];
$kartenid = 1;
$id = 1;
// Prepare the INSERT statement
$stmt = $conn->prepare("INSERT INTO benutzer (VorName, NachName, KartenID, E-MailAdresse,AdressenID, Passwort) VALUES ('". $vorname ."' , '". $nachname ."' ,'". $kartenid ."' , '". $email ."', '". $id ."','". $passwort ."')");
// Execute the statement
if ($stmt->execute()) {
echo "Data inserted successfully.";
} else {
echo "Error inserting data: " . $stmt->error;
}
// Close the statement and connection
$stmt->close();
$conn->close();
?>

View File

@ -1,6 +1,10 @@
<?php <?php
$db_link = mysqli_connect('localhost', 'web_b-3', 'een7Ao6s', 'bibliothek_candle', '3306'); $db_link = mysqli_connect('localhost', 'web_b-3', 'een7Ao6s', 'bibliothek_candle', '3306');
if(!$db_link){
die("<p>Verbindung nicht hergestellt</p>");
}else{
echo("<p>Verbindung wurde hergestellt</p>");
}
function runSQL($sql){ function runSQL($sql){
global $db_link; global $db_link;
$db_res = mysqli_query($db_link, $sql) or die("SQL_Abfrage: " . $sql . "Fehler: " . mysqli_error($db_link)); $db_res = mysqli_query($db_link, $sql) or die("SQL_Abfrage: " . $sql . "Fehler: " . mysqli_error($db_link));
@ -8,42 +12,4 @@
} }
$kartenid = 1000000000000000;
function register($vorname,
$nachname ,
$strasse,
$hausnummer,
$plz,
$ort,
$emailrep,
$email,
$passwort,
$passwortrep){
global $db_link;
$vorname = mysqli_real_escape_string($db_link, $vorname);
$nachname = mysqli_real_escape_string($db_link, $nachname);
$email = mysqli_real_escape_string($db_link, $email);
$passwort = md5( $passwort);
$ort = mysqli_real_escape_string($db_link, $ort);
$plz = mysqli_real_escape_string($db_link, $plz);
$strasse = mysqli_real_escape_string($db_link, $strasse);
$hausnummer = mysqli_real_escape_string($db_link, $hausnummer);
//Benutzer schon vorhanden?
$db_res = runSQL("SELECT COUNT(*) FROM benutzer WHERE E-MailAdresse='" . $email . "'");
$row = mysqli_fetch_array($db_res);
if($row['COUNT(*)'] > 0)
{
return 'Es gibt schon einen Benutzer mit der angegebenen E-Mail Adresse';
}
runSQL("INSERT INTO benutzer (VorName, NachName, KartenID, E-MailAdresse, Passwort) VALUES ('". $vorname ."' , '". $nachname ."' ,'". $kartenid ."' , '". $email ."', '". $passwort ."')");
runSQL("INSERT INTO adresse (Stadt, Postleitzahl, Straße, Hausnummer) VALUES ('". $ort ."' , '". $plz ."' ,'". $strasse ."' , '". $hausnummer ."')");
$kartenid = $kartenid + 1;
}
?> ?>

View File

@ -1,5 +1,7 @@
<?php <?php
session_start(); session_start();
require('anmeldesystem.php');
require('connect_db.php');
if(isset($_POST['Registrieren'])){ if(isset($_POST['Registrieren'])){
$vorname = $_POST["vorName"]; $vorname = $_POST["vorName"];
$nachname = $_POST['nachName']; $nachname = $_POST['nachName'];
@ -191,62 +193,19 @@ if(isset($_POST['Registrieren'])){
</body> </body>
</html>'; </html>';
$db_link = mysqli_connect('localhost', 'web_b-3', 'een7Ao6s', 'bibliothek_candle', '3306');
function runSQL($sql){ $erg = register($vorname,
global $db_link;
$db_res = mysqli_query($db_link, $sql) or die("SQL_Abfrage: " . $sql . "Fehler: " . mysqli_error($db_link));
return $db_res;
}
$kartenid = 1000000000000000;
function register($vorname,
$nachname ,
$strasse,
$hausnummer,
$plz,
$ort,
$emailrep,
$email,
$passwort,
$passwortrep){
global $db_link;
$vorname = mysqli_real_escape_string($db_link, $vorname);
$nachname = mysqli_real_escape_string($db_link, $nachname);
$email = mysqli_real_escape_string($db_link, $email);
$passwort = md5( $passwort);
$ort = mysqli_real_escape_string($db_link, $ort);
$plz = mysqli_real_escape_string($db_link, $plz);
$strasse = mysqli_real_escape_string($db_link, $strasse);
$hausnummer = mysqli_real_escape_string($db_link, $hausnummer);
//Benutzer schon vorhanden?
$db_res = runSQL("SELECT COUNT(*) FROM benutzer WHERE E-MailAdresse='" . $email . "'");
$row = mysqli_fetch_array($db_res);
if($row['COUNT(*)'] > 0)
{
return 'Es gibt schon einen Benutzer mit der angegebenen E-Mail Adresse';
}
runSQL("INSERT INTO benutzer (VorName, NachName, KartenID, E-MailAdresse, Passwort) VALUES ('". $vorname ."' , '". $nachname ."' ,'". $kartenid ."' , '". $email ."', '". $passwort ."')");
runSQL("INSERT INTO adresse (Stadt, Postleitzahl, Straße, Hausnummer) VALUES ('". $ort ."' , '". $plz ."' ,'". $strasse ."' , '". $hausnummer ."')");
$kartenid = $kartenid + 1;
}
register($vorname,
$nachname , $nachname ,
$strasse, $strasse,
$hausnummer, $hausnummer,
$plz, $plz,
$ort, $ort,
$emailrep,
$email, $email,
$passwort, $passwort,);
$passwortrep);
echo '<p> . $erg . </p>';
} }