0

I got the warning mentioned in the title and my code is here:Warning: mysqli_select_db() expects parameter 1 to be MySQLi, string given in /CDC/slider.php on line 3

slider.php

<?php require_once('db/dbcon.php'); ?>

<?php mysqli_select_db($database_dbcon, $dbcon);
$query_slide ="SELECT * FROM photos_slide_tb";
$slide  = mysqli_query($query_slide , $dbcon) or die(mysqli_error());
$row_slide = mysqli_fetch_assoc($slide );
$totalRows_slide  = mysqli_num_rows($slide ); ?>

    <div id="sliderFrame">
        <div id="slider">
        <?php if ($totalRows_slide == 0) { ?><h1>&nbsp;</h1>
            <h1 align="center">Not available</h1>

        <?php } else do { ?> 
            <img src="photos/<?php echo $row_slide['location'];?>"  alt="<?php echo $row_slide['caption'];?>" />
        <?php } while ($row_slide = mysqli_fetch_assoc($slide)); ?>
        </div>

        <div id="htmlcaption" style="display: none;">
        </div>
    </div>

dbcon.php

<?php
$hostname_dbcon = "localhost";
$database_dbcon = "123";
$username_dbcon = "123";
$password_dbcon = "123";
$dbcon = mysqli_connect($hostname_dbcon, $username_dbcon, $password_dbcon) or trigger_error(mysqli_error(), E_USER_ERROR); 
?>
NoNaMe
  • 6,020
  • 30
  • 82
  • 110

4 Answers4

0

Correct params order is $connection, $db_name:

mysqli_select_db($dbcon, $database_dbcon);
pavel
  • 26,538
  • 10
  • 45
  • 61
  • another warning appear on line 5 Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /CDC/slider.php on line 5 – El Presidente May 06 '15 at 07:13
  • @ElPresidente: the same, first param has to be connectin link, the second SQL query. `mysqli_query($dbcon, $query_slide)`. – pavel May 06 '15 at 07:14
0

Passing wrong parameters. The first parameter is the connection object & the second parameter is the database name.

mysqli_select_db($dbcon, "Datebase Name");

Do the same for mysqli_query()

mysqli_query($dbcon, $query_slide);
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
  • another warning appear on line 5 Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /CDC/slider.php on line 5 – El Presidente May 06 '15 at 07:13
  • here http://stackoverflow.com/questions/30094244/log-in-page-looks-like-not-redirecting-to-the-next-page-how-do-i-fix-this/30094306#30094306 – El Presidente May 07 '15 at 07:18
0

You have placed arguments to mysqli_select_db() incorrectly.

Corrected one is:

mysqli_select_db($dbcon, $database_dbcon);

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

Pupil
  • 23,834
  • 6
  • 44
  • 66
  • another warning appear on line 5 Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /CDC/slider.php on line 5 – El Presidente May 06 '15 at 07:13
0

Correct params over both function

mysqli_select_db($database_dbcon, $dbcon);

should be

mysqli_select_db($dbcon,$database_dbcon);

and another

mysqli_query($query_slide , $dbcon)

should be

mysqli_query($dbcon, $query_slide)
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54