0

Sorry for the newbie question, but I am working on my first PHP script and I can't seem to make it work. I just want to display the records from a single MySQL table. I have been trying to do this for ages and it is not displaying anything except the first two echo statements, before it is supposed to pull out the data.

What am I doing wrong?

<?php
  mysql_connect("localhost", "me", "mypass") or die(mysql_error());
  echo "Connection to the server was successful!<br/>";

  mysql_select_db("test") or die(mysql_error());
  echo "Database was selected!<br/>";

  $result = mysql_query("SELECT * FROM Customer");

  while($row = mysql_fetch_assoc($result)){
  echo "ID: ".$row['customer_id'].", Name:".$row['customer_name']
  ."<br/>";
  }
?>
Kallaste
  • 737
  • 1
  • 9
  • 18
  • Maybe the query is getting an error. Add `or die(mysql_error())` to the end of the `mysql_query()` line. – Barmar Nov 18 '14 at 00:59
  • Or maybe there's nothing in the Customer table. – Barmar Nov 18 '14 at 01:00
  • If you're new, you should learn good habits off the bat. Don't use the obsolete `mysql_XXX` functions, learn `PDO` or `mysqli`. – Barmar Nov 18 '14 at 01:01
  • I did it, and you're right--it says "table test.Customer doesn't exist." I am trying to figure out what is wrong . . . – Kallaste Nov 18 '14 at 01:02
  • On Linux, table names are case-sensitive. So if the table is named `CUSTOMER` or `customer`, `Customer` won't work. – Barmar Nov 18 '14 at 01:03
  • possible duplicate of [Why shouldn't I use mysql\_\* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – dynamic Nov 18 '14 at 01:05
  • Aha! The database name was test1, not test. I can't believe I missed that. I just kept looking for syntax errors. Thank you very much, really. – Kallaste Nov 18 '14 at 01:05

2 Answers2

0
echo mysql_num_rows($result);

to know the number of rows returned by your query.

0

This error is because the table or the database you are trying to connect doesnt exits.

As @barmar suggests table names are case sensitive..

Please make sure that you are using the correct database and table ..THanx

Avinash Babu
  • 6,171
  • 3
  • 21
  • 26