You are here: I have a weird database problem: it is returning spurious rows with all the fields concatenated into one « PHP Programming Language « IT news, forums, messages
I have a weird database problem: it is returning spurious rows with all the fields concatenated into one

Posted by Jeff Silverman on 11/03/00 11:41

I have a PHP program that almost works. I'm running it from the command
line and simulating a form using a GET method. That part is working,
but I get spurious records with all of the fields concatenated into a
single field.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="content-type">
<title>eqdb_read.php - Read the Equipment Database</title>
</head>
<body>
<small>This document last modified
<script>document.writeln(document.lastModified)</script>.</small>

<?php
$_GET['hostname'] = $argv[1]; // grab [1] because [0] holds the script
name FOR DEVELOPMENT ON THE COMMAND LINE ONLY

$hostname = $_GET['hostname'];
if ( is_null($hostname) ) {
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
Host Name:
<input type="text" name="hostname" /> <br />
<input type="submit" name="Lookup by hostname" />
</form>

<?php
} else {
require_once('DB.php');
$dsn = "mysql://read@black/equipment_test";
print("Connecting to database $dsn <br>\n");
$db=DB::connect($dsn, array('debug'=>1 ));
if (DB::iserror($db)) {
die($db->getMessage());
};
print("Connected. Looking up $hostname <br/>\n");
$sql = "SELECT name, location, kernel, distribution, sysadmin, ip,
mac, vendor_sn, real_num
FROM computers WHERE name LIKE '".$hostname."%' ORDER BY name ASC";

$q = $db->query($sql);
if ( DB::iserror($q)) {
die( $q->getMessage());
}
print("Completed the query<br><br>");


// generate the table
?>
<table>
<tr>
<th>name</th>
<th>location</th>
<th>kernel</th>
<th>distribution</th>
<th>sysadmin</th>
<th>ip</th>
<th>mac</th>
<th>vendor_sn</th>
<th>real_num</th>
</tr>
<?php
while ( $row = $q->fetchRow() ) {
if ( DB::isError($row) ) {
die ( $row->getMessage() );
}
print(" <tr>\n");
for ($field=0; $field<4; $field++ ) {
print(" <td>$row[$field] </td>\n");
};
print(" </tr>\n");
}
$db->disconnect();
}

?>
</table>
</body>
</html>

When I run the program, I get no error messages, but I get spurious records:

[jeffs@black public_html]$ php eqdb_read.php 238lvs | more
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="content-type">
<title>eqdb_read.php - Read the Equipment Database</title>
</head>
<body>
<small>This document last modified
<script>document.writeln(document.lastModified)</script>.</small>

Connecting to database mysql://read@black/equipment_test <br>
Connected. Looking up 238lvs <br/>
Completed the query<br><br><table>
<tr>
<th>name</th>
<th>location</th>
<th>kernel</th>
<th>distribution</th>
<th>sysadmin</th>
<th>ip</th>
<th>mac</th>
<th>vendor_sn</th>
<th>real_num</th>
</tr>
<tr>
<td>238lvs01.prognet.com N debian Linux 2.4.20 prod
Se </td> <---- this is incorrect!!!!
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<------ This is okay!!!!!
<td>238lvs01.prognet.com </td>
<td>Seattle,MSR,C05,43 </td>
<td>Linux 2.4.20 </td>
<td>debian </td>
<td>ISO </td>
<td>192.168.238.25 </td>
<td>00:03:47:84:D6:63 </td>
<td> </td>
</tr>
<tr>
<td>238lvs02.prognet.com N debian Linux 2.4.20 prod
Se </td> <------- this is INCORRECT!!!!!!!!
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>238lvs02.prognet.com </td>
<-------- This is okay!!!!
<td>Seattle,MSR,C05,28 </td>
<td>Linux 2.4.20 </td>
<td>debian </td>
<td>ISO </td>
<td>192.168.238.112 </td>
<td>00:03:47:7C:25:CE </td>
<td> </td>
</tr>
</table>
</body>
</html>
[jeffs@black public_html]$

I don't get it. Does anybody have an insight?


Many thanks,


Jeff Silverman

jeff aat commercialventvac d0t com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация