您好,我正在尝试使用'post‘将三个下拉列表中的值传递到使用php脚本的数据库中,其中我使用三个列表的值将值插入到数据库中
以前,我使用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");
?>发布于 2013-09-22 23:36:12
如果您想检索div内容,如input,请选择etc
你必须像这样理解它
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){
}
});
});
});https://stackoverflow.com/questions/18945482
复制相似问题