Jump to content

PHP and Mysql connection problem...


muffin100

Recommended Posts

I have a script like this:

[code]
<?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>";
?>
[/code]

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?
Link to comment
https://forums.phpfreaks.com/topic/24293-php-and-mysql-connection-problem/
Share on other sites

You need to query the database first.  Try this:

[code]
<?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)
[/code]

Regards
Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.