Jump to content

Recommended Posts

I am not a programmer but I am trying to learn mysql, php and some html.  I am just trying to pull some data from an exsiting mysql table:

 

mysql> show create table servers ;
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| servers | CREATE TABLE `servers` (
  `server_name` varchar(25) NOT NULL,
  `source` varchar(50) DEFAULT NULL,
  `rto` varchar(10) DEFAULT NULL,
  `hardware_platform` varchar(15) DEFAULT NULL,
  `status` varchar(25) DEFAULT NULL,
  `category` varchar(25) DEFAULT NULL,
  `function_type` varchar(25) DEFAULT NULL,
  `machine_role` varchar(100) DEFAULT NULL,
  `notes` varchar(255) DEFAULT NULL,
  `domain` varchar(35) DEFAULT NULL,
  `os` varchar(50) DEFAULT NULL,
  `service_pack` varchar(15) DEFAULT NULL,
  `manufacturer` varchar(15) DEFAULT NULL,
  `machine_model_name` varchar(25) DEFAULT NULL,
  `machine_type` varchar(20) DEFAULT NULL,
  `machine_model` varchar(20) DEFAULT NULL,
  `proposed_decommission_date` datetime DEFAULT NULL,
  `decommission_company` varchar(25) DEFAULT NULL,
  `decommission_id` varchar(25) DEFAULT NULL,
  `decommission_pu_date` datetime DEFAULT NULL,
  `build_method` varchar(15) DEFAULT NULL,
  PRIMARY KEY (`server_name`),
  KEY `decommission_id` (`decommission_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.

 

 

 

here is my first php that I put together from some examples and it's not pulling any data from the table.  I can login with the same credentials and pull the information with the select but the .php gives me no data.  I was wondering if someone could help me with what I am doing wrong:

 

version       | 5.1.69

 

<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = 'passw0rd';
$database = 'testdata';
$connector = mysql_pconnect($db_host, $db_user, $db_pwd) or trigger_error(mysql_error(),E_USER_ERROR);
$table = 'servers';

mysql_select_db($database, $connector);//This connects and selects proper database
$query = "SELECT * FROM servers";//This is the query that is sent to MySQL

$result = mysql_query($query, $connector) or die(mysql_error()); //Sends the query to the database
$row_Details = mysql_fetch_assoc($result); //Grabs the first record of the returned data
$fields_num = mysql_num_fields($result); //Returns a count of the returned records - Not really going to use this unless you want to use this for loops or to display a record count

?>
<html><head><title>MySQL Table Viewer</title></head><body>

<table border='1' width="900">
<tr>
<td align="center">Server Name</td>
<td align="center">Platform</td>
<td align="center">RTO</td>
<td align="center">Domain</td>
<td align="center">Operating System</td>
<td align="center">Service Pack</td>
<td align="center">Status</td>
<td align="center">Category</td>
</tr>
 <?php do { ?>
<tr>
<td align="center"><? echo $row_Details['server_name'];?></td>
<td align="center"><? echo $row_Details['platform'];?></td>
<td align="center"><? echo $row_Details['rto'];?></td>
<td align="center"><? echo $row_Details['domain'];?></td>
<td align="center"><? echo $row_Details['os'];?></td>
<td align="center"><? echo $row_Details['service_pack'];?></td>
<td align="center"><? echo $row_Details['status'];?></td>
<td align="center"><? echo $row_Details['category'];?></td>
</tr>
<?php } while ($row_Details = mysql_fetch_assoc($result)); ?>
<tr>
<td colspan="8" align="right">Total Records Returned: <? echo $fields_num;?>
</table>
<?
mysql_free_result($result);
?>
</body>
</html>

 

 

 

Thank you in advance if anyone could help me with this.

 

 

 

 

 

 

 

 

 

Side notes:

Is there a reason you're using persistent connections? If you don't need them, you could just use mysql_connect():

http://us3.php.net/manual/en/function.mysql-connect.php

 

Also note that the mysql_ function have been depreciated. It's time to start considering the alternatives:

http://us3.php.net/manual/en/mysqlinfo.api.choosing.php

I just found some code and tried to put my first .php together without success so I am open to suggestions.  I thought if I could start with a fairly simple .php I could go from there but that didn't work.  I will look at your other links that you you posted to see if I can get this to work and then hopefully build on it from there.  I was hoping to get my initiial .php to work initially but that didn't work so far.

Usually adding someone's code and trying to get it to work majority of the time ends in failure and/or leads to sloppy insecure code. Personally the best course of action is get a up-to-date book on php that focuses on the beginner to intermediate level programmer. Just my .02 cents

 

 

Or if you want to go the online route websites such as this : http://teamtreehouse.com/join/first-week-free?cid=1027&gclid=CN65uaj2zboCFeY-Mgod8S0AgQ can get you started in the right direction. There are free websites or ones that have limited free tutorials out there on the website, just do a Google search.

Edited by Strider64
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.