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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.