1

I have query like below

function getConnected($host,$user,$pass,$db) {

   $mysqli = new mysqli($host, $user, $pass, $db);

   if($mysqli->connect_error) 
     die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());

   return $mysqli;
}

$sqli= getConnected('localhost','db','pass','user');



    if ($data = $sqli->query("INSERT INTO `buy_diet`.`rcat` (`cat`, `id`) VALUES ('$cat', '$idea');")) {
     echo $data;
    }
    else
    {
    echo "fail";
    }

above code always failing..database is connected and all other queries like select , update etc are working fine , But INSERT query is failing...I have tried to copy the exact statement and run the query in phpmyadmin ,its working but not in above php code.

So how can I debug whats the problem.Right now I get only this error (bool)false , How to see detailed error.

Vishnu
  • 2,372
  • 6
  • 36
  • 58
  • Have you tried printing the SQL in the script itself just for debugging purpose? and then try to run that printed query in the db directly and see if it gives any error. – Pratip Ghosh Dec 30 '14 at 12:31

2 Answers2

1

Replace echo "fail" with echo $sqli->error to see the actual problem.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
0

Just look at the mysql error log file to get the exact problem. To get the log file use this link How to see log files in MySQL?

Community
  • 1
  • 1
Kiren S
  • 3,037
  • 7
  • 41
  • 69