PHP Tutorials: Register & Login (Part 4): Database Connection




Want more? Explore the library at https://www.codecourse.com/lessons Official site https://www.codecourse.com Twitter https://twitter.com/teamcodecourse.

Original source


25 responses to “PHP Tutorials: Register & Login (Part 4): Database Connection”

  1. Everything worked up until i added include 'core/init.php'; in my index.php now i get a blank screen when i refresh index.php.
    here is my index .php
    <?php

    include 'core/init.php';
    include 'includes/overall/header.php';
    ?>

    <h1>home</h1>
    <p>template</p>

    <?php include 'includes/overall/footer.php'; ?>

    and my init.php

    <?php

    session_start();
    error_reporting(0);

    require 'database/connect.php';
    ?>

    and my connect.php

    <?php

    $connect_error = 'sorry, we're expirencing connection problems.';

    mysql_connect('localhost', 'root', '') or die ($connect_error);
    mysql_select_db('gl') or die ($connect_error);
    ?>

  2. Use this code if anyone face any error while connecting database!

    <?php
    $conn = mysqli_connect("localhost", "root", "", "DatabaseName");
    if (!$conn) {
    # code…
    die("Connection failed: ".mysqli_connect_error());
    }
    ?>

  3. Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at C:xampphtdocswanderlustindex.php:14) in C:xampphtdocswanderlustcoreinit.php on line 2

  4. For those who are having trouble with mysql connect, try this:

    <?php

    $DBhost = "localhost";
    $DBuser = "root";
    $DBpass = "";
    $DBname = "dbname";

    $DBcon = new MySQLi($DBhost,$DBuser,$DBpass,$DBname);

    if ($DBcon->connect_errno) {
    die("ERROR : > ".$DBcon>connect_error);
    }

  5. Hi, I have declared $error on the init.php, however, when I include "core/init.php" on the login page it displays a blank page and I cannot implement $error array variable in a login page can someone please help me?

  6. I hope that you will revisit this tutorial for a new update.  As of the latest release of MySQL (as of 2015) there is a message that coders will see when writing out the commands:  "Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead"

    This is a real issue because they no longer be available, and everyone will have to upgrade to MySQLi or PDO.  The change will be drastic as MySQLi uses a different method of connecting to databases than traditional MySQL.

  7. im getting :

    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at F:xampplitehtdocslibrarymain.php:2) in F:xampplitehtdocslibrarycoreinit.php on line 2

    How do i fix this?

  8. Random question but my stylesheet wont work with my page anymore. Well it does but when I try putting new values into it then it wont work so I have to do inline styles…. Help?

  9. This worked for me if you are having problems with the connect.php file

    <?php
    $connect_error = 'Error message';
    $con = mysqli_connect('localhost','root','');
    mysqli_select_db($con,'test') or die($connect_error);
    ?>

  10. Deprecated mysql_, and include continues where require shows errors: In connect.php, replace mysql_connect and the next line with: mysqli_connect('localhost','root','','lr') or die($connect_error);
    then in index.php change include 'core/init.php'; into require ''core/init.php';.
    When you change the params of mysqli_connect to check errors, it will show the error msg.

Leave a Reply