Jump to content


Photo

PHP and Mysql connection problem...


  • Please log in to reply
3 replies to this topic

#1 muffin100

muffin100
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 18 October 2006 - 02:47 AM

I have a script like this:

<?php
mysql_connect('10.0.35.4','testuser','test');
mysql_select_db('helpdesk');

$result="SELECT * FROM login";
$row=mysql_fetch_array($result);

// 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
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 3.23.49
MYSQL_MODULE_TYPE builtin
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_INCLUDE no value
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

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:

<?php
mysql_connect('10.0.35.4','testuser','test');
mysql_select_db('helpdesk');

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

Regards
Huggie
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

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

ruano84
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationVenezuela

Posted 18 October 2006 - 10:50 PM

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

echo mysql_error();

Bye
Alexis RR




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users