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.