-4
$result = mysql_query("SELECT name FROM internet_shop");
while($row=mysql_fetch_assoc($result))

Its shows errors mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in

Databsename:piashhas_piash

One table in database: internet_shop

Runs well in local host Xampp but when on server it shows error can anyone help thanks

Abhik Chakraborty
  • 43,914
  • 5
  • 48
  • 61
Piash Hassan
  • 49
  • 1
  • 1
  • 6
  • 1
    1) `mysql_*` functions are deprecated, use `mysqli` or PDO. 2) What does `mysql_error` print (since `mysql_query` obviously returns FALSE)? – ccKep May 11 '14 at 22:00
  • it says no database selected – Piash Hassan May 11 '14 at 22:03
  • Then you should look back at your `mysql_select_db` **and its return values**. In any case: You should rewrite your code using non-deprecated functions. – ccKep May 11 '14 at 22:04

1 Answers1

1

Alter the query line to

$result = mysql_query("SELECT name FROM internet_shop") or exit(mysql_error());

Is an error displayed? As ccKep stated, MySQL is deprecated; consider MySQLi.

$connectionId = mysqli_connect($host,$user,$pass) or exit(mysqli_connect_error());
mysqli_select_db($connectionId, "piashhas_piash") or exit(mysqli_error($connectionId));
$result = mysqli_query($connectionId, "SELECT `name` FROM `internet_shop`");
while($row=mysqli_fetch_assoc($result))
  • @PiashHassan Don't forget to accept the answer. Accepted answers make supporters happy! ;) – ccKep May 11 '14 at 22:40