0

我似乎无法找出为什么我的 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>
4

2 回答 2

1

您的基本问题是您希望 value 是选择下拉列表中所有值的总和。表单提交不是这样工作的。您需要分别获取每个选定选项的值,然后将它们相加。像这样的东西:

$value = 0;
$value += $_GET["Quad"];
$value += $_GET["Lion"];
$value += $_GET["Gym"];
$value += $_GET["Meal"];
$value += $_GET["Private"];

这将位于图像标签之前,并将采用“Quad”选择的选定值并将其添加到总数中。然后它将采用“Lion”选择的值并对其进行处理,等等。

这并不漂亮,但它应该让您朝着正确的方向前进,并让您了解表单是如何提交的。

于 2012-05-02T21:20:44.663 回答
-1

看起来您没有用实际值填充 $value 。

将以下内容放在 $dorm=dorm 之前:

$value = $_GET["value"]

假设您正在调用结果脚本,例如 results.php?value=50

于 2012-05-02T20:53:19.117 回答