CageyJ0nnY Posted May 19, 2010 Share Posted May 19, 2010 I have created an array that stores values in a table. I do not know why the values are not being stored in the table but rather outside of it. here is the code: <?php $conn = mysql_connect('jjennings3db.bimserver2.com', 'jjennings3db', 'bullet5646546541'); mysql_select_db('jjennings3db', $conn); $sql = "SELECT * FROM tblProperties WHERE id=".$_GET[id]; $result1 = mysql_query($sql, $conn); $array1 = mysql_fetch_array($result1); ?> <html> <head> <title>Properties</title> </head> <body> <table width="640" border="2" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="3" align="center"><h1>Property</h1></td> </tr> <tr> <td align="left" valign="top"><strong>Address:</strong></td> <td align="left" valign="top">PropertyName</td> <td rowspan="2" align="center"valign="middle">book cover picture</td> <?php echo '$array1[PropertyName]'; ?> </tr> <tr> <td align="left" valign="top"><strong>Location:</strong></td> <td align="left" valign="top">Location</td> <?php echo '$array1[Location]'; ?> </td> <tr> <td align="left" valign="top"><strong>Property Price:</strong></td> <td align="left" valign="top">SalePrice</td> <?php echo '$array1[salePrice]'; ?> </td> <tr> <td colspan="3" align="center" valign="top"><a href="http://jjennings3.bimserver2.com/links.php">back to list of Properties</a> </td> </tr> </table> </body> </html> any help would be appreciated Jonny Link to comment https://forums.phpfreaks.com/topic/202275-array-table-help/ Share on other sites More sharing options...
gwolgamott Posted May 19, 2010 Share Posted May 19, 2010 <tr> </td> You've some mismatched opened and closed tags <table width="640" border="2" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="3" align="center"><h1>Property</h1></td> </tr> <tr> <td align="left" valign="top"><strong>Address:</strong></td> <td align="left" valign="top">PropertyName</td> <td rowspan="2" align="center"valign="middle">book cover picture</td> <?php echo '$array1[PropertyName]'; ?> </tr> <tr> <! -- /////////////////////////////opened a <tr> but never closed --> <td align="left" valign="top"><strong>Location:</strong></td> <td align="left" valign="top">Location</td> <?php echo '$array1[Location]'; ?> </td> <!-- //////////////closed a <td> but never opened --> <tr> <!-- //////////same as above --> <td align="left" valign="top"><strong>Property Price:</strong></td> <td align="left" valign="top">SalePrice</td> <?php echo '$array1[salePrice]'; ?> </td> <!-- /////////////// same as above --> <tr> <td colspan="3" align="center" valign="top"><a href="http://jjennings3.bimserver2.com/links.php">back to list of Properties</a> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/202275-array-table-help/#findComment-1060720 Share on other sites More sharing options...
Psycho Posted May 19, 2010 Share Posted May 19, 2010 Well, you are not echoing the values within a table cell (i.e. TD tags). Also fixed: - You are also not escaping the user submitted ID value - this could cause a malicious user to use sql injection to cause havoc to your data. Fixed using mysql_real_escape_string() - Changed the name of the array to a more logical value. - Fixed the query to only get the values yuou need to be more efficient - Properly formatted the array values - i.e. the index is enclosed in quote marks <?php $conn = mysql_connect('jjennings3db.bimserver2.com', 'jjennings3db', 'bullet5646546541'); mysql_select_db('jjennings3db', $conn); $id = mysql_real_escape_string($_GET[id]); $sql = "SELECT PropertyName, Location, SalePrice FROM tblProperties WHERE id={$id}";$result1 = mysql_query($sql, $conn); $property = mysql_fetch_array($result1); ?> <html> <head> <title>Properties</title> </head> <body> <table width="640" border="2" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="3" align="center"><h1>Property</h1></td> </tr> <tr> <td align="left" valign="top"><strong>Address:</strong></td> <td align="left" valign="top">PropertyName</td> <td rowspan="2" align="center"valign="middle">book cover picture</td> <td><?php echo $property['PropertyName']; ?></td> </tr> <tr> <td align="left" valign="top"><strong>Location:</strong></td> <td align="left" valign="top">Location</td> <td><?php echo $property['Location']; ?></td> </tr> <tr> <td align="left" valign="top"><strong>Property Price:</strong></td> <td align="left" valign="top">SalePrice</td> <td><?php echo $property['SalePrice']; ?></td> </tr> <tr> <td colspan="3" align="center" valign="top"> <a href="http://jjennings3.bimserver2.com/links.php">back to list of Properties</a> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/202275-array-table-help/#findComment-1060725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.