I think the problem you're having is because you're combining object-oriented and non-OO calls to the MySQLi library.
The mysqli_error()
function does indeed require a parameter -- it requires the connection variable; in your case, $conn
.
mysqli_error($conn)
Howwever, if you'd written it in an OO manner, as you have done for most of the rest of the database calls, you would have written it like this:
$conn->error
Since all the rest of your code is written using object-oriented calls, it would make sense to use it for this call as well.
So your full line of code would look like this:
$result = $conn->query($sql) or die($conn->error);
You can see further examples in the PHP manual: http://php.net/manual/en/mysqli.error.php
Hope that helps.
With regard your question about the book you're using: I can't comment directly on the book itself as I haven't read it. But note that there are two MySQL libraries for PHP; the older mysql
library, and the newer mysqli
library. The older library also has a mysql_error()
function, which differs from the newer one in that it does not require a connection variable. If there is an error in the book you are using, this may be the source of the confusion.