Jump to content


PHP and Mysql connection problem...

  • Please log in to reply
3 replies to this topic

#1 muffin100

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 18 October 2006 - 02:47 AM

I have a script like this:


$result="SELECT * FROM login";

// display the 8 columns of results in a table by
// looping through the array of results, $result,

   print "<body bgcolor='ffeecc'>";
   echo "<table>";
   do {
       echo "<tr>";
       echo "<td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2];
       echo "</td><td>".$row[3]."</td>";
       echo "</tr>";
} while ($row= mysql_fetch_array($result));

   print "</table></body>";

but the problem is that nothing shows on the page, it should show the all the data in the login database and now it's only showing a background colour and not even a table. I have no problem using:
SELECT * from login;
on the mysql prompt on the server with the testuser. Here is the Mysql info of the phpinfo page:

MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 3.23.49
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_LIBS no value

Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host   no value no value
mysql.default_password no value no value
mysql.default_port   no value no value
mysql.default_socket no value no value
mysql.default_user   no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode         Off Off
Is there anything wrong with the installation?
By the way is there another ways of testing for PHP connection to Mysql?

#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 October 2006 - 02:55 AM

You need to query the database first.  Try this:


$sql="SELECT * FROM login";
$result = mysql_query($sql); // This was what you were missing
$row = mysql_fetch_array($result)

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 muffin100

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 18 October 2006 - 10:45 PM

I changed the code to the one you provided but the page is still blank.
I reckon it's a connection problem through PHP and Mysql.

You have other suggestions?
Thanks anyway

#4 ruano84

  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationVenezuela

Posted 18 October 2006 - 10:50 PM

I suggest to write this line of code after each function of mysql:

echo mysql_error();

Alexis RR

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users