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.

1
  • 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. Commented Dec 30, 2014 at 12:31

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks :) I had not given the user previlage of insert
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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.