Jump to content
khiles

A PHP Error was encountered

Recommended Posts

Hi all trying to help a friend with a script his installing

 

but keep getting two errors

Severity: Warning
Message: mysqli_query() expects at least 2 parameters, 1 given

and
Severity: Warning
Message: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given

 

the code being run is

 

  <?php
		    $sql="SELECT * FROM `adminlogin` WHERE role='admin'";
                    $qry=mysqli_query($sql);
                    $data=mysqli_fetch_array($qry);
                    ?>

not sure what I'm doing wrong any help would be appreciated

 

full page source is

 

<header  id="header-navbar">
    <div class="container" >
        <a style="background-color: #2a3133" href="<?php echo base_url();?>admin/dashboard" id="logo" class="navbar-brand">
            <img src="<?php echo base_url();?>upload/taxi_logo.png" alt="" class="normal-logo logo-white" width="100%" height="100%"/>
<!--            <img src="img/logo-black.png" alt="" class="normal-logo logo-black"/>-->
<!--            <img src="img/logo-small.png" alt="" class="small-logo hidden-xs hidden-sm hidden"/>-->
        </a>

        <div  class="clearfix">
            <button class="navbar-toggle" data-target=".navbar-ex1-collapse" data-toggle="collapse" type="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="fa fa-bars"></span>
            </button>

            <div class="nav-no-collapse navbar-left pull-left hidden-sm hidden-xs">
                <ul class="nav navbar-nav pull-left">
                    <li>
                        <a class="btn" id="make-small-nav">
                            <i class="fa fa-bars"></i>
                        </a>
                    </li>
<!--                    <li class="dropdown hidden-xs">-->
<!--                        <a class="btn dropdown-toggle" data-toggle="dropdown">-->
<!--                            <i class="fa fa-bell"></i>-->
<!--                            <span class="count">8</span>-->
<!--                        </a>-->
<!--                        <ul class="dropdown-menu notifications-list">-->
<!--                            <li class="pointer">-->
<!--                                <div class="pointer-inner">-->
<!--                                    <div class="arrow"></div>-->
<!--                                </div>-->
<!--                            </li>-->
<!--                            <li class="item-header">You have 6 new notifications</li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-comment"></i>-->
<!--                                    <span class="content">New comment on ‘Awesome P...</span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-plus"></i>-->
<!--                                    <span class="content">New user registration</span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-envelope"></i>-->
<!--                                    <span class="content">New Message from George</span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-shopping-cart"></i>-->
<!--                                    <span class="content">New purchase</span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-eye"></i>-->
<!--                                    <span class="content">New order</span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item-footer">-->
<!--                                <a href="#">-->
<!--                                    View all notifications-->
<!--                                </a>-->
<!--                            </li>-->
<!--                        </ul>-->
<!--                    </li>-->
<!--                    <li class="dropdown hidden-xs">-->
<!--                        <a class="btn dropdown-toggle" data-toggle="dropdown">-->
<!--                            <i class="fa fa-envelope-o"></i>-->
<!--                            <span class="count">16</span>-->
<!--                        </a>-->
<!--                        <ul class="dropdown-menu notifications-list messages-list">-->
<!--                            <li class="pointer">-->
<!--                                <div class="pointer-inner">-->
<!--                                    <div class="arrow"></div>-->
<!--                                </div>-->
<!--                            </li>-->
<!--                            <li class="item first-item">-->
<!--                                <a href="#">-->
<!--                                    <img src="img/samples/messages-photo-1.png" alt=""/>-->
<!--                                        <span class="content">-->
<!--                                            <span class="content-headline">-->
<!--                                                George Clooney-->
<!--                                            </span>-->
<!--                                            <span class="content-text">-->
<!--                                                Look, just because I don't be givin' no man a foot massage don't make it-->
<!--                                                right for Marsellus to throw...-->
<!--                                            </span>-->
<!--                                        </span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <img src="img/samples/messages-photo-2.png" alt=""/>-->
<!--                                        <span class="content">-->
<!--                                            <span class="content-headline">-->
<!--                                                Emma Watson-->
<!--                                            </span>-->
<!--                                            <span class="content-text">-->
<!--                                                Look, just because I don't be givin' no man a foot massage don't make it-->
<!--                                                right for Marsellus to throw...-->
<!--                                            </span>-->
<!--                                        </span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <img src="img/samples/messages-photo-3.png" alt=""/>-->
<!--                                        <span class="content">-->
<!--                                            <span class="content-headline">-->
<!--                                                Robert Downey Jr.-->
<!--                                            </span>-->
<!--                                            <span class="content-text">-->
<!--                                                Look, just because I don't be givin' no man a foot massage don't make it-->
<!--                                                right for Marsellus to throw...-->
<!--                                            </span>-->
<!--                                        </span>-->
<!--                                    <span class="time"><i class="fa fa-clock-o"></i>13 min.</span>-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item-footer">-->
<!--                                <a href="#">-->
<!--                                    View all messages-->
<!--                                </a>-->
<!--                            </li>-->
<!--                        </ul>-->
<!--                    </li>-->
<!--                    <li class="dropdown hidden-xs">-->
<!--                        <a class="btn dropdown-toggle" data-toggle="dropdown">-->
<!--                            New Item-->
<!--                            <i class="fa fa-caret-down"></i>-->
<!--                        </a>-->
<!--                        <ul class="dropdown-menu">-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-archive"></i>-->
<!--                                    New Product-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-shopping-cart"></i>-->
<!--                                    New Order-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-sitemap"></i>-->
<!--                                    New Category-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    <i class="fa fa-file-text"></i>-->
<!--                                    New Page-->
<!--                                </a>-->
<!--                            </li>-->
<!--                        </ul>-->
<!--                    </li>-->
<!--                    <li class="dropdown hidden-xs">-->
<!--                        <a class="btn dropdown-toggle" data-toggle="dropdown">-->
<!--                            English-->
<!--                            <i class="fa fa-caret-down"></i>-->
<!--                        </a>-->
<!--                        <ul class="dropdown-menu">-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    Spanish-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    German-->
<!--                                </a>-->
<!--                            </li>-->
<!--                            <li class="item">-->
<!--                                <a href="#">-->
<!--                                    Italian-->
<!--                                </a>-->
<!--                            </li>-->
<!--                        </ul>-->
<!--                    </li>-->
<!--                    <span class="conveythis notranslate" translate="no"><a href="http://translation-services-usa.com/spanish.php" title="spanish translation services" class="conveythis-image conveythis-drop translate1">spanish translation services</a></span><script src="http://s1.conveythis.com/e4/javascript/e.js?conveythis_src=en"></script>-->
                </ul>
            </div>

            <div class="nav-no-collapse pull-right" id="header-nav">
                <ul class="nav navbar-nav pull-right">
                    <li class="mobile-search">
                        <a class="btn">
                            <i class="fa fa-search"></i>
                        </a>

                        <div class="drowdown-search">
                            <form role="search">
                                <div class="form-group">
                                    <input type="text" id="example1" class="form-control" placeholder="Search...">
                                    <i class="fa fa-search nav-search-icon"></i>
                                </div>
                            </form>
                        </div>

                    </li>
                    <?php
		    $sql="SELECT * FROM `adminlogin` WHERE role='admin'";
                    $qry=mysqli_query($sql);
                    $data=mysqli_fetch_array($qry);
                    ?>
                    <li class="dropdown profile-dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <img src="<?php echo base_url().$data['image']; ?>" alt=""/>
                            <span class="hidden-xs"><?php echo $data['username'];?></span> <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-right">
                            <li><a href="profile"><i class="fa fa-user"></i>Profile</a></li>
                            <li><a href="password_change"><i class="fa fa-cog"></i>Change Password</a></li>
<!--                            <li><a href="#"><i class="fa fa-envelope-o"></i>Messages</a></li>-->
                            <li><a href="logout"><i class="fa fa-power-off"></i>Logout</a></li>
                        </ul>
                    </li>
                    <li class="hidden-xxs">
                        <a class="btn" href="logout">
                            <i class="fa fa-power-off"></i>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</header>

 

Share this post


Link to post
Share on other sites

Having read the error message, were you not tempted to read the reference manual for mysqli_query() to see what the correct parameters should be?

  • Like 1

Share this post


Link to post
Share on other sites

Was the code using the mysql_* functions previously? And someone found out they needed to upgrade to the mysqli_* functions? Did they think it was just a matter of adding an 'i' in the function names? If it was and they did, they're wrong: it's almost just a matter of adding the 'i'.

  • Like 1

Share this post


Link to post
Share on other sites

from what i understand yes i have not used mysql in years and lots has changed i believe he said without adding the i the script would not run

Share this post


Link to post
Share on other sites
30 minutes ago, khiles said:

from what i understand yes i have not used mysql in years and lots has changed i believe he said without adding the i the script would not run

And he's right. But what he may have neglected to mention is that adding the 'i' is not enough. Check out the documentation Barand linked to.

  • Like 1

Share this post


Link to post
Share on other sites

thank you for all your help got it working

 

ps: is there a better way to pull database details from another file 

 

ie

 

include 'application/config/database.php';
                    $db = new mysqli('localhost','user','pass','data');

 

inside database.php is

$db["default"]["hostname"] = "localhost";
$db["default"]["username"] = "root";
$db["default"]["password"] = "password";
$db["default"]["database"] = "database";
$db["default"]["dbdriver"] = "mysqli";
$db["default"]["dbprefix"] = "";
$db["default"]["pconnect"] = TRUE;
$db["default"]["db_debug"] = FALSE;
$db["default"]["cache_on"] = FALSE;
$db["default"]["cachedir"] = "";
$db["default"]["char_set"] = "utf8";
$db["default"]["dbcollat"] = "utf8_general_ci";
$db["default"]["swap_pre"] = "";
$db["default"]["autoinit"] = TRUE;
$db["default"]["stricton"] = FALSE;

im not sure its possible but so i can put   $db = new mysqli('["hostname"]',["username"]',["pass"]',["database"]');

 

Thank you again for all your help 

Share this post


Link to post
Share on other sites

I have mine set up like this

<?php
// DEFINE CONNECTION CREDENTIALS
    const HOST = 'localhost';
    const USERNAME = 'user';
    const PASSWORD = 'pwd';
    const DBNAME = 'dbname';
    
// MYSQLI CONNECTION
    function myConnect($dbname=DBNAME)
    {
        mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
        $db = mysqli_connect(HOST,USERNAME,PASSWORD,$dbname);
        $db->set_charset('utf8');
        return $db;
    }

//PDO CONNECTION
    function pdoConnect($dbname=DBNAME)
    {
        $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        return $db;    
    }

Then if I want a mysqli connection

require 'database.php';
$db = myConnect();

and for a PDO connection (strongly recommended)

require 'database.php';
$db = pdoConnect();

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.