-1

I am getting warning --> mysql_fetch_array() expects parameter 1 to be resource, boolean

enter code here
$db // database name
$sql1="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND       TABLE_SCHEMA=".$db." order by create_time desc limit 1";
$res1 = mysql_query($sql1);
if($row = mysql_fetch_array($res1))
echo $row['TABLE_NAME'];
else echo "unable to fetch table name";
Aditya Goel
  • 13
  • 2
  • 6

1 Answers1

2

You need to put quotes around the inclusion of the $db variable. Change this line:

$sql1="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND       TABLE_SCHEMA=".$db." order by create_time desc limit 1";

To:

$sql1="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND       TABLE_SCHEMA='".$db."' order by create_time desc limit 1";

Note that mysql_* functions are deprecated. Use PDO or mysqli_* with prepared statements to avoid security risks in your applications.

Community
  • 1
  • 1
  • 1
    To make your answer more interesting for future visitors it would be good to explain the difference between the two lines (ie, the quoting of `$db`) – fvu Dec 28 '14 at 11:02
  • @fvu yes, you are right, sometimes I give long answers and explanations as on [here](http://security.stackexchange.com/questions/76946/how-are-random-numbers-for-rsa-generated/76952#76952) but in this question it is just a syntaxic error. please, edidt my answer if you see there is something to explain better –  Dec 28 '14 at 11:04