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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘