我真的坚持这个问题,我已经全力以赴,我仍然无法解决什么错误,甚至我的朋友都试图帮助我,我开始认为它无法解决......这就是什么希望
创建一个名为task3a.php的PHP脚本,用于检索每个驱动程序的名称和ID,并输出 信息与前两个任务不同。输出应该包含,而不是显示表 一个HTML表单。表单应包含提交按钮和下拉列表输入。下拉菜单 输入应包含驱动程序名称,表单应通过GET方法提交给task4.php 按下提交按钮时。命名选择输入驱动程序。
这就是我所拥有的 -
<!DOCTYPE HTMl>
<html>
<body>
<?php
try {
$dbhandle = new PDO('mysql:host=<...>.ac.uk;dbname=user','user','pass');
} catch (PDOExeption $e) {
die('Error Connecting to Database: ' . $e->getMessage());
}
$driver = 'SELECT forename, surname, d.nationality, name FROM Drivers d JOIN Teams t ON d.id = t.id';
$query = $dbhandle->prepare($driver);
if ($query->execute() === FALSE ) {
die('Error Running Query: ' . implode($query->errorInfo(), ' '));
}
$query->execute();
$result = $query->fetchAll();
?>
<table>
<tr>
<th>Forename</th>
<th>Surname</th>
<th>Nationality</th>
<th>Team</th>
</tr>
<?php foreach($result as $row) { ?>
<tr>
<td><?php echo $row['forename']; ?></td>
<td><?php echo $row['surname']; ?></td>
<td><?php echo $row['nationality']; ?><td>
<td><?php echo $row['name']; ?></td>
</tr>
<?php } ?>
</table>
<form action='task3a.php' method='GET'>
<select name=''driver>
<?php foreach($results as $row) { ?>
<option value='<?php echo $row['id'];?>' > <?php echo $row['name']; ?> </option>
<?php } ?>
</select>
</form>
</body>
</html>
它给了我一张桌子,里面有一切都在里面,然后在它下面一个没有任何东西的下拉框,我很困惑
答案 0 :(得分:1)
考虑更改此
<select name=''driver>
到
<select name='driver'>
答案 1 :(得分:1)
$result = $query->fetchAll();
^--- no S
<?php foreach($result as $row) { ?>
^---no S
<?php foreach($results as $row) { ?>
^----where did this S come from?