0

有人可以告诉我如何将选择下拉值与我的文本输入值一起发布到 mysql 数据库中。

我有以下内容,但不确定应如何处理下拉值。

谢谢

<form action=\"includes/welcomestats.php\" method=\"post\" id=\"form1\">            

    <input type=\"text\" name=\"location\" id=\"location\" maxlength=\"30\" placeholder=\"Location: e.g. London\">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter Your Location</label><br/>
    <br/>

    <input type=\"text\" name=\"local_station\" id=\"local_station\" maxlength=\"30\" placeholder=\"Local Train Station\"><label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter a Local Train Station</label><br/><br/><br/>

    <h5>About You</h5><br/>
    <select name=\"formGender\" style=\"min-width:125px;\">
      <option value=\"\">Select...</option>
      <option value=\"M\">Male</option>
      <option value=\"T\">Female</option>
    </select>
    <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter Your Gender</label>
    <br/><br/>

    <input type=\"submit\" class=\"welcome-submit2\" name=\"submit\" value=\"Next ->\" id=\"submit\"/>
    </form>


    <?php
    require_once("session.php"); 
    require_once("functions.php");
    require('_config/connection.php');
    ?>
    <?php 
    session_start();
    include '_config/connection.php'; 
    $location = $_POST['location'];
    $result = mysql_query("SELECT location FROM ptb_profiles WHERE id=".$_SESSION['user_id']."");
    if(!$result) 
    { 
    echo "The username you entered does not exist"; 
    } 
    else 
    if($location!= mysql_result($result, 0)) 
    { 
    echo ""; 
        $sql=mysql_query("UPDATE ptb_profiles SET location ='".addslashes($display_name)."' WHERE id=".$_SESSION['user_id'].""); 

    }
4

1 回答 1

0

选择字段值的处理方式与任何其他字段相同。因此,如果您有选择字段,例如-

    <select name=\"formGender\" style=\"min-width:125px;\">
      <option value=\"\">Select...</option>
      <option value=\"M\">Male</option>
      <option value=\"T\">Female</option>
    </select>

您可以使用

      $gender = $_POST['formGender']

更新 这将为您提供 M 或 F。

于 2013-02-03T15:25:05.470 回答