1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Rep Power

    Stuck on mysqli [very short code]

    started learning php last week, at first didn't know anything about it so used mysql, now yesterday reading some article i saw that i should be using mysqli instead of mysql, so i changed all the code for my registration and login pages every works fine. However can't figure out the mysql_result to mysqli, couldn't find it on google too

    the code:
    the error im getting:
    Warning: mysql_result() expects parameter 1 to be resource, object given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 12

    require 'conect.php';

    $user_ip = $_SERVER['REMOTE_ADDR'];

    function update_count()
    { global $dbconnect;

    $query = "SELECT count FROM hits_count";
    if ($query_run = mysqli_query($dbconnect, $query))
    $count = mysql_result($query_run, 0, 'count');
    echo $count;
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    you cannot mix the old MySQL extension with MySQLi. They're incompatible and have nothing to do with each other.

    Also you cannot fetch a single field in MySQLi. You can fetch a whole row and then extract the field from it:

    PHP Code:
    list($count) = mysqli_fetch_row($query_run); 
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo