I have a strange problem. I inserted the database connection into a separate .php file. If I insert this php file now as include, the function will not be executed anymore (in this case register). The funny thing about it is, at the login.php he took it over and it works. Additionally, if I add the content of dbconnection.php to the register.php file, it works. Only the include command doesn't work.
Here's the code:
dbconnection.php:
$db = new mysqli('xxx', 'xxx', 'xxx', 'xx');
if($db->connect_error):
echo $db->connect_error;
endif;
login.php which is working:
<?php
include ('dbconnection.php');
if(isset($_POST['absenden'])):
$benutzername = strtolower($_POST['benutzername']);
$passwort = $_POST['passwort'];
$passwort = md5($passwort);
$search_user = $db->prepare("SELECT id FROM users WHERE benutzername = ? AND passwort = ?");
$search_user->bind_param('ss',$benutzername,$passwort);
$search_user->execute();
$search_result = $search_user->get_result();
if($search_result->num_rows == 1):
$search_object = $search_result->fetch_object();
$_SESSION['user'] = $search_object->id;
header('Location: '.$_SERVER['PHP_SELF']);
else:
echo 'Deine Angaben sind leider nicht korrekt!';
endif;
endif;
register.php which is not working (White screen, if I add the content of dbconnection.php (without include) to register.php, it works.):
<?php
include ('dbconnection.php');
$benutzername = $_POST['benutzername'];
$passwort = $_POST['passwort'];
$passwort_widerholen = $_POST['passwort_widerholen'];
$search_user = $db->prepare("SELECT id FROM users WHERE benutzername = ?");
$search_user->bind_param('s',$benutzername);
$search_user->execute();
$search_result = $search_user->get_result();
if($search_result->num_rows == 0):
if($passwort == $passwort_widerholen):
$passwort = md5($passwort);
$insert = $db->prepare("INSERT INTO users (benutzername,passwort) VALUES (?,?)");
$insert->bind_param('ss',$benutzername,$passwort);
$insert->execute();
if($insert !== false):
echo 'Dein Account wurde Erfolgreich erstellt! <a href="index.php?page=anmelden">HIER</a> kannst du dich anmelden.';
endif;
else:
echo 'Deine Passwörter stimmen nicht überein!';
endif;
else:
echo 'Der Benutzername ist leider schon vergeben!';
endif;
endif;