用户使用表单和 php 从下拉菜单中进行选择后重定向到特定网页


Redirect to a specific webpage after users select from dropdown menu using a form and php

我正在为一个朋友开发一个网页,他租车,所以我想要下拉菜单和一个提交按钮,用户可以在其中选择他们正在寻找的汽车类型。

例:

type of car:
- Small
- Medium
- Large
Price Range:
- $100
- $200
- $300

并根据条件将它们重定向到特定页面。我很确定我可以使用 html 格式的表单将其存档,就像我目前拥有的

表单一样
<form action="php/cars.php" method="post" enctype="multipart/form-data" name="frmdata">
<table width="100%">
  <tr>
    <td valign="top">
    <select id="type" name="type">
        <option value="1" data-description="Small Car">Small Car/option>
        <option value="2" data-description="Medium Car">Medium Car</option>
        <option value="3" data-description="Large Car">Large Car</option>
    </select>
    <select name="price" id="price">
      <option value="a">100</option>
      <option value="b">200</option>
      <option value="c">300</option>
    </select>
    </td>
  </tr>
  <tr>
    <td valign="bottom"><input type="submit" value="Submit" /></td>
  </tr>

现在,问题出在我的 php 中,

我做错了什么?它确实加载了 php,所以问题不在 html 中。此外,如果有更好的方法来实现这一目标,我已经准备好了:)

<?php
switch ($_POST['type'].$_POST['price']) {
    case "1a":
        $redirectLocation = "http://google.com";
    case "2a":
        $redirectLocation = "http://apple.com";
}
?> 

您实际上从未执行重定向:

<?php
switch ($_POST['type'].$_POST['price']) {
    case "1a":
        $redirectLocation = "http://google.com";
        break;
    case "2a":
        $redirectLocation = "http://apple.com";
        break;
}
header('Location: ' . $redirectLocation);
exit;
?> 
尝试 else 条件

首先接受来自用户的输入,将其传递给 PAGE 然后检查条件 if 和 else . 然后重定向他