3

My following code is working on my local host server. when I host it to actual server the query is not working though connection was established.
output was

"result problem"

<?php
include_once 'db_connect.php'; 

class test{
    public function test1(){
        $db_connect = new db_connect();
        $con = $db_connect->connect();
        if(!$con){
            echo "connection fail";
        }else{
            $sql = "select * from tbl_admin where name='abc' ";
            $query = mysqli_query($con,$sql);
            if(!$query){
                    echo "result problem";
                }else{
                        $result = mysqli_fetch_array($query);
                        echo $result['ad_tp'];
                    }
        }
    }
}

$t = new test();
$t->test1();
Federico
  • 3,782
  • 32
  • 46
GHH197
  • 33
  • 9

2 Answers2

3

Replace

echo "result problem";

with

printf("Errormessage: %s\n", mysqli_error($link));

This will get you an exact idea of why query is not executing.

Arpita
  • 1,386
  • 1
  • 15
  • 35
  • Thanx Arpita;It printed only "Errormessage:" wot's the meaning of "Function name must be a string in test.php on line 14" line 14 is "echo "mysqli query error " . $mysqli_error($con);" – GHH197 Oct 26 '15 at 09:20
  • Remove $ from $mysqli_error from line 14 – Rumi Oct 26 '15 at 09:38
  • Thanx Rumi.. it does not show any error... $ part should be there.. – GHH197 Oct 26 '15 at 10:08
0

Use MySQL's mysqli_error to find the MySQL error:

if(!$query){
    echo("Error description: " . mysqli_error($con));
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20