khiles Posted November 5, 2019 Share Posted November 5, 2019 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> Quote Link to comment https://forums.phpfreaks.com/topic/309465-a-php-error-was-encountered/ Share on other sites More sharing options...
Barand Posted November 5, 2019 Share Posted November 5, 2019 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? 1 Quote Link to comment https://forums.phpfreaks.com/topic/309465-a-php-error-was-encountered/#findComment-1571244 Share on other sites More sharing options...
requinix Posted November 5, 2019 Share Posted November 5, 2019 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'. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309465-a-php-error-was-encountered/#findComment-1571246 Share on other sites More sharing options...
khiles Posted November 5, 2019 Author Share Posted November 5, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309465-a-php-error-was-encountered/#findComment-1571247 Share on other sites More sharing options...
requinix Posted November 5, 2019 Share Posted November 5, 2019 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309465-a-php-error-was-encountered/#findComment-1571248 Share on other sites More sharing options...
khiles Posted November 5, 2019 Author Share Posted November 5, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309465-a-php-error-was-encountered/#findComment-1571252 Share on other sites More sharing options...
Barand Posted November 5, 2019 Share Posted November 5, 2019 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(); Quote Link to comment https://forums.phpfreaks.com/topic/309465-a-php-error-was-encountered/#findComment-1571254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.