我似乎无法找出为什么我的PHP不会与我的HTML链接。想法是根据调查弹出某些图片。例如,如果数字加起来超过50,将弹出“bromley.jpg”。虽然只是说“宿舍”而不是图片,但这种情况并没有发生。
<!DOCTYPE html>
<html>
<head>
<title> Find the right dorm for you </title>
<h1>Find out what dorm fits your lifestyle!</h1>
</head>
<body>
<p> Please fill out a few quesitons so we can help you figure out which dorm is best for you. </p>
<form method="get" action="slutsky1-results.php">
I enjoy (check all that apply):<br>
<input type="checkbox" name="act1" value="8">Working Out<br>
<input type="checkbox" name="act2" value="3">Bowling<br>
<input type="checkbox" name="act3" value="3">Live Music<br>
<input type="checkbox" name="act4" value="5">Shopping<br>
<input type="checkbox" name="act5" value="7">Food<br>
<input type="checkbox" name="act6" value="9">Bars <br>
<input type="checkbox" name="act7" value="9">Frat Parties <br>
<input type="checkbox" name="act8" value="8">Sports <br>
<input type="checkbox" name="act9" value="3">Library <br>
Is being close to the quad important to you?:
<select name= "Quad">
<option value="1">Not important</option>
<option value="3">Kind of important</option>
<option value="6">Very Important</option>
<option value="3">Only thing that matters</option>
</select>
<br>
How often do you plan on going to Red Lion?:
<select name= "Lion">
<option value="1">Never</option>
<option value="5">Sometimes</option>
<option value="10">Over 3 times a week</option>
</select>
<br>
Would you rather go to the ARC or CRCE?:
<select name= "Gym">
<option value="10">Arc</option>
<option value="1">CRCE</option>
</select>
<br>
How do you plan on eating most of your meals?:
<select name= "Gym">
<option value="5">Ordering delivery</option>
<option value="8">Walking To Green St.</option>
<option value="5">Making my own food</option>
</select>
<br>
Private or Public dorm?:
<select name= "Gym">
<option value="10">Private</option>
<option value="5">Public</option>
</select>
<br>
<input type="submit" value="get my results!">
</form>
</body>
</html>
slutsky1-results.php:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title> Dorm results! </title>
</head>
<body>
<h1> Your ideal dorm based on your answers is...</h1>
<p>
<?php
// Generates answer based on total numbers accumuated throughout survey.
$dorm= dorm ;
echo "Our reccomendation is $dorm <br>";
?>
<img src="<?php
if ($value > 50 ){
echo "bromley" ;
}
else if ($value>15 && $value <31) {
echo "Allen" ;
}
else if ($value>30 && $value <50) {
echo "peabody" ;
}
else if ($value>0 && $value <16) {
echo "PAR FAR" ;
}
?>.jpg">
</p>
</body>
</html>
答案 0 :(得分:1)
您的基本问题是您希望值是选择下拉列表中所有值的总和。表单提交不起作用。您需要单独获取每个选定选项的值,然后将其添加。像这样:
$value = 0;
$value += $_GET["Quad"];
$value += $_GET["Lion"];
$value += $_GET["Gym"];
$value += $_GET["Meal"];
$value += $_GET["Private"];
这将在图像标记之前,并将选择“Quad”选择的值并将其添加到总计。那么它将取“狮子”选择的价值等等。
这不是很好,但它应该让你朝着正确的方向前进,并让你了解表格的提交方式。
答案 1 :(得分:-1)
看起来你没有用实际值填充$ value。
在$ dorm = dorm:
之前加上以下内容$ value = $ _GET [“value”]
假设您正在调用结果脚本,例如results.php?value = 50