-1

Can you please help me with this?

var_dump($result);

always returns

bool(false)

Why is that?

Here is my query:

$query="INSERT INTO inzeraty (nazov, price) VALUES (" .$nazov ."," .$price .")";
$result= mysqli_query($mysqli,$query);
var_dump($result);
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Need to provide more detail. It could be number of things, starting with your connection. Don't see `$mysqli` in this snippit, are you sure your connection to db is successful? – bos570 Feb 22 '18 at 16:55
  • 4
    I'm gonna go out on a limb and say that `nazov` is a `VARCHAR` and the value needs to be quoted. – Patrick Q Feb 22 '18 at 16:56
  • @PatrickQ solid guess. – bos570 Feb 22 '18 at 16:57
  • I'm curious to know why you used a PDO method with a prepared statement in your previous post https://stackoverflow.com/q/48080944/1415724 then veered off to using the mysqli_ api and without a prepared statement. You did the same error on both here. – Funk Forty Niner Feb 22 '18 at 17:08

2 Answers2

0

mysqli_query Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

Since you are doing an INSERT mysqli_query could return TRUEif the insert was successful, but in your case is FALSE so it failed.

See more here

lloiacono
  • 4,714
  • 2
  • 30
  • 46
0

It returns false because there was an error.

Check the sintax:

$query="INSERT INTO inzeraty (nazov, price) VALUES ('" .$nazov ."',"' 
.$price ."')";

You have a double quote before the single quote. Use this:

$query="INSERT INTO inzeraty (nazov, price) VALUES ('" .$nazov ."','" 
.$price ."')";

In case the query was successful it will return true or an object.

Check documentation: http://php.net/manual/en/mysqli.query.php