0

I am new to php and try to make login form but their will be error while make a connection.i didn't get it.

<?php

 // this will avoid mysql_connect() deprecation error.
 error_reporting( ~E_DEPRECATED & ~E_NOTICE );
 // but I strongly suggest you to use PDO or MySQLi.

define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'simple_login');

$conn = mysqli_connect(DBHOST,DBUSER,DBPASS);
$dbcon = mysqli_select_db(DBNAME,$conn);

if ( !$conn ) {
 die("Connection failed : " . mysqli_error());
 }

if ( !$dbcon ) {
 die("Database Connection failed : " . mysqli_error());
 }

please if anybody know help me.thanks in advance.

Prit
  • 31
  • 1
  • 4

2 Answers2

1

Need to pass first parameter as connection then your database name

mysqli_select_db ($conn, DBNAME );

Read http://php.net/manual/en/mysqli.select-db.php

Check connection error as

 /* check connection */
     if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
        }
Saty
  • 22,443
  • 7
  • 33
  • 51
0

Try This below code:

You have to pass first $conn when select the DB, you have changed the parameter order.

<?php

 // this will avoid mysql_connect() deprecation error.
 error_reporting( ~E_DEPRECATED & ~E_NOTICE );
 // but I strongly suggest you to use PDO or MySQLi.

define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'simple_login');

$conn = mysqli_connect(DBHOST,DBUSER,DBPASS);
$dbcon = mysqli_select_db($conn,DBNAME);

if ( !$conn ) {
 die("Connection failed : " . mysqli_connect_errno());
 }

if ( !$dbcon ) {
 die("Database Connection failed : " . mysqli_connect_errno());
 }

Hope this help!!

mageDev0688
  • 566
  • 4
  • 27