doujin8673 2017-11-08 01:54
浏览 32
已采纳

麻省病麻烦[重复]

This question already has an answer here:

Hello i am trying to get my form to say the corresponding price per day based upon the destination chosen on my drop down menu. It currently shows "Your base price is $50 per day" for all three of the destination options. I am new to php and setting up forms so forgive me if it is very off.

// html code

<div class="form-group">
<label> Travel Destination: </label>
<select name="travDest">
    <option value="Mexico">Mexico</option>
    <option value="Alaska">Alaska</option>
    <option value="Carribean">Carribean</option>
</select>
</div>


// php code

$travDest = $_GET["travDest"];

if ($_GET['travDest']) {
    echo "You will be traveling to 
".htmlspecialchars($_GET['travDest']);
}
else {
    return false;
}

if ($_GET["travDest"] = "Mexico") {
    echo "<br>Your base price is $50 per day";
}
else if ($_GET["travDest"] = "Alaska") {
    echo "<br>Your base price is $100 per day";
}
else if ($travDest = "Carribean") {
    echo "<br>Your base price is $75 per day";
}
else {
    return false;
}
</div>
  • 写回答

1条回答 默认 最新

  • dongsonglian7303 2017-11-08 01:57
    关注

    Read the difference between = and ==.

    In your if statements, you use single =, which means you are assigning $_GET["travDest"] to "Mexico". Since the assignment worked, it returned TRUE, so the if is satisfied and prints the 50$ per day price.

    Switch to == in your if statements, you will see a huge difference!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。