du3932066 2013-06-10 12:32
浏览 28
已采纳

将值从下拉框发送到另一个页面

I have the following drop down box. I want to be able to select a value from this box and using Php sending it to another page.

this is my current code for drop dwon box:

version2:

<form style="margin-top:20px; margin-right:+50px" name="formname" method="post" action="search.php">
<div class="controls controls-row">
<select name="select1" id="select1"> 
<option value="SelectIsland">Select your island</option>
<option value="stMaarten">St. Maarten</option>
<option value="Aruba">Aruba</option>
<option value="Curacou">Curacou</option>
<option value="StBarths">St. Barths</option>
</select>   

<select name="select2"> 
<option value="SelectLoc">Select your location</option>
<option value="Philipsburg">Philipsburg</option>
<option value="SimpsonBay">Simpson Bay</option>
<option value="Maho">Maho</option>
<option value="Cupecoy">Cupecoy</option>
<option value="Middleregion">Middle region</option>
<option value="MadameEstate">Madame Estate</option>
<option value="StPeters">St. Peters</option>
<option value="DawnBeach">Dawn Beach</option>
</select>
<input type="submit" name="button" class="btn btn-primary" value="Find Restaurant" style="margin-top:-10px; margin-right:0px" />
</div>
<?php 
$select1 = $_POST['select1'];
?>
</form>

I am trying to pass $select1 to search.php, using this: $select1 = $_POST['select1'];

however I get this following error, without doing anything: Notice: Undefined index: select1 in C:\wamp\www\iLandgrub.com V 1.2\main page\index.php on line 194, on y index.php.

If I remove $select1 = $_POST['select1']; then it will work but on search.php I dont get the values I wanted.

this my code in search.php:

the same applies for select2, as well. I am already in my index.php withut doing anything I get the error Undefined index.

<?php
if(isset($_POST['select1']) && isset($_POST['select2'])) {
$select1 = $_GET['select1'];
$select2 = $_GET['select2'];
echo $select1;
echo "";
echo $select2;
}
else{
echo "not set";
}
?> 

enter image description here this is the error in index.php, when you go to this page.

  • 写回答

5条回答 默认 最新

  • douxing9228 2013-06-10 12:34
    关注

    That's because you're using an anchor element. Change

    <a href="search.php" class="btn btn-primary" style="margin-top:-10px; margin-right:0px"type="button" name="button">Find Restaurant</a>
    

    to

    <input type="submit" class="btn btn-primary" value="Find Restaurant" />
    

    This will post the form data to search.php - if you want the page to submit to itself, change action="search.php" to action="".

    Note: you will need to change your CSS to style the button in the same way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包