0

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;
  • What happens if you remove the space after the `include`? – Predrag Beocanin Jan 27 '19 at 18:59
  • Possible duplicate of [PHP's white screen of death](https://stackoverflow.com/questions/1475297/phps-white-screen-of-death) – Progman Jan 27 '19 at 19:00
  • Has no effect on –  Jan 27 '19 at 19:00
  • Do not use `md5()` for hashing passwords, use `password_hash()`/`password_verify()` instead. See https://stackoverflow.com/questions/30279321/how-to-use-password-hash – Progman Jan 27 '19 at 19:02
  • @Progman Thanks for the tip, but unfortunately it doesn't solve the problem. –  Jan 27 '19 at 19:09
  • 1
    do you have error reporting on - any error messages? – lovelace Jan 27 '19 at 19:10
  • No error message, there is a white screen and this code is still being executed: `if(isset($_SESSION['user'])): require_once('ui.php'); else: if($page == 'anmelden'): echo 'Doch registrieren?'; require_once('anmelden.php'); elseif($page == 'registrieren'): echo 'Doch anmelden?'; require_once('registrieren.php'); else: echo 'Hey! Willst du dich anmelden oder registrieren?'; endif; endif; ` –  Jan 27 '19 at 19:16

1 Answers1

-3

that's may be due to relative path issues of your included db file. check your project directory structure and relative path