0

I have a problem, I looked for it on google, couldn't find it.

$result = mysqli_query($link,"SELECT * FROM  update ");

Error

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in

When I change the query to:

$result = mysqli_query($link,"SELECT * FROM  `update` ");

It works. Why is that?

Lohn Claidon
  • 405
  • 2
  • 7
  • 15

4 Answers4

4

update is a reserved word in MySQL.

You should always use backticks

`

in `table` and `column` names to avoid errors like that.

List of Reserved Words

Emilio Gort
  • 3,475
  • 3
  • 29
  • 44
3

Those are not "grave accents" (accents go above letters); they are backticks.

You're supposed to surround field names with backticks, to show that they are field names and not functions, operators, commands, etc.

You can usually get away without doing that (and it would seem that you are quite used to it!), but in the case that your names are in fact MySQL reserved keywords — for example, UPDATE — you can't.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

UPDATE is a keyword for MySQL, so it cause an error (mysql is pretty confused because you're starting update inside select). Basically its recommended to put database, table and column names between `` to avoid such situations, also you should check what mysqli_query did return, in this case you're getting false instead of mysqli_result object and you can read an error message (probably not saying much more than 'you have an error near... check your query syntax', but anyway you would know that there is something wrong ;)) :

if (!($result = mysqli_query($link, $query))) {
    die('MySQLi error: ' . mysqli_error($link));
}
lupatus
  • 4,208
  • 17
  • 19
0

I'm no SQL expert, but update is a special word which SQL actively looks for. Therefore, the select stuff in a table named update, you need to have update in quotes.

Undo
  • 25,519
  • 37
  • 106
  • 129