我的单选按钮在网页上不可见

时间:2015-01-28 03:12:48

标签: php mysql

我正在使用“PHP and SQL for dummies 4th edition”这本书来学习网络编程。我的PetCatalog界面用于检索和显示我的数据库中的所有petType。它正在检索数据库中的宠物,但它没有单选按钮。我不知道错误来自哪里,因为代码中的所有内容似乎都已到位。 注意:除了没有显示单选按钮符号外,一切都很完美。 PS:这个程序需要一个虚构的数据库才能让任何想要帮助的人都感觉到,因为数据库在我的系统中。谢谢。

<?php
/* Program: PetCatalog.php
* Desc: Displays a list of pet categories from the
* PetType table. Includes descriptions.
* Displays radio buttons for user to check.
*/
?>
<html>
<head><title>Pet Types</title></head>
<body>
<?php
$user="root";
$host="localhost";
$password="";
$database="PetCatalog";
$cxn = mysqli_connect($host,$user,$password,$database) 
or die ("couldn't connect to server");
/* Select all categories from PetType table */
$query = "SELECT * FROM PetType ORDER BY petType"; 
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query.");
/* Display text before form */
echo "<div style='margin-left: .1in'>\n
<h1 style='text-align: center'>Pet Catalog</h1>\n
<h2 style='text-align: center'>The following animal
friends are waiting for you.</h2>\n
<p style='text-align: center'>Find just what you want
and hurry in to the store to pick up your
new friend.</p>
<h3>Which pet are you interested in?</h3>\n";
/* Create form containing selection list */
echo "<form action='ShowPets.php' method='POST'>\n";
echo "<table cellpadding='5' border='1'>";
$counter=1; 
while($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "<tr><td valign='top' width='15%'
style='font-weight: bold;
font-size:1.2em'\n";

echo "<input type='radio' name='interest' value='$petType'\n"; 
if( $counter == 1 )
{
echo "checked='checked'";
}

echo ">$petType</td>"; 
echo "<td>$typeDescription</td></tr>";
$counter++;
}
echo "</table>";
echo "<p><input type='submit' value='Select Pet Type'>
</form></p>\n"; 
?>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:3)

首先突然出现的是你的

echo "<tr><td valign='top' width='15%'
style='font-weight: bold;
font-size:1.2em'\n";

不会关闭<td>标记。这可能会干扰您创建<input>代码。

尝试

echo "<tr><td valign='top' width='15%'
style='font-weight: bold;
font-size:1.2em'>\n";

看看是否有效。

答案 1 :(得分:0)

就像justathoughtor2说关闭表数据和表行</td></tr>我已经测试了你没有关闭表数据和表行 no radio buttons

关闭表数据和表行后 enter image description here

相关问题