Sunday, 15 February 2015

sql - php select from table error -



sql - php select from table error -

this question has reply here:

mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row() expects parameter 1 resource or mysqli_result, boolean given 32 answers

i have problem.

when seek select info table using code:

$sql = "select * users"; $result = mysql_query($sql); while($rad = mysql_fetch_array($result)) { echo $rad['user']; }

it works.

when select info table same code error.

$sql = "select * order"; $result = mysql_query($sql); while($rad = mysql_fetch_array($result)) { echo $rad['url']; }

can please tell me i'm doing wrong here.

this error message when run sec code:

warning: mysql_fetch_array() expects parameter 1 resource, boolean given in

your result returning false , meaning there error in query.

from php.net:

for select, show, describe, explain , other statements returning resultset, mysql_query() returns resource on success, or false on error.

it's possible have no rights on table.

do show me error:

$sql = "select * order"; $result = mysql_query($sql); echo mysql_error();

problem found:

after seeing mysql error clear.

you have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'order' @ line 1

you have chance:

$sql = "select * order";

to

$sql = "select * `order`";

putting order between backticks (“`”), because order reserved mysql word order by operations.

reserved words permitted identifiers if quote them described in section 9.2, “schema object names”:

from mysql.com

reserved words listed @ section 9.3, “reserved words”.

php sql message

No comments:

Post a Comment