0

嗨,我正在尝试使用 php 脚本将三个下拉列表中的“post”值传递到数据库,在该脚本中,我使用三个列表的值将值插入数据库

以前我使用 jquery ajax 调用从另一个页面将列表检索到 div time.php

看起来像这样的代码:-

//This script uses jquery and ajax it is used to set the values in
// the time field whenever a day is selected.
$(document).ready(function(){                               
    $("#day").change(function(){                

          var day=$("#day").val();
          var doctor=$("#doctor").val();

          $.ajax({
              type:"post",
              url:"time.php",
              data:"day="+day+"&doctor="+doctor,
              success:function(data){
                 $("#time").html(data);
                 }

          });

    });
});

html 部分的代码如下所示:-

<select id="doctor">some options</select>
<select id="day">some options</select>
<div id="time"> </div>

现在两个列表中的值都很好。但是我检索到 div 的那个没有通过。你能指出我正确的方向吗?提前致谢。

   //The php script for insertion

    <?php
session_start();                  //Use this to include session variables
$con=mysqli_connect("localhost","clinic","myclinic","myclinic");
    // Check connection

    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $query = "INSERT INTO appointment(username, doctor, day, time) VALUES('$_SESSION[username]', '$_POST[doctor]', '$_POST[day]', '$_POST[time]')";

    if (!mysqli_query($con,$query))
    {
        die('Error: ' . mysqli_error($con));
    }


    mysqli_close($con);
    header("location:login_success.php");
         ?>
4

1 回答 1

0

如果您想检索 div 内容,如输入、选择等

你必须得到它喜欢

var time = $("#time").html();

您的代码将是

向页面添加按钮

<input type='button' value='Send' id='send'>

然后加

$(document).ready(function(){                               
    $("#send").click(function(){                

          var day=$("#day").val();
          var doctor=$("#doctor").val();
          var time = $("#time").find("select").val();

          $.ajax({
              type:"post",
              url:"time.php",
              data:"day="+day+"&doctor="+doctor+"&time="+time, //add param
              success:function(data){

                 }

          });

    });
});
于 2013-09-22T15:36:11.567 回答