
正文
php下拉框数据库 php下拉表单
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php中下拉框的值怎样写入数据库中
form method=post
select name='sel'
option value=11/option
option value=22/option
/select
/form
?php
echo $_POST['sel']; //这样就能获取到select的值了~
?
相关问答
Q1: 如何php下拉菜单显示数据库记录,并把选中的值传递给另一个页面使用?
首先呢php下拉框数据库,php下拉框数据库我先说一下,你php下拉框数据库的sql语句报错是因为你要查询php下拉框数据库的time是一个字符串,要用引号,不然会报错
其次呢,你既然想在这边下拉表单选择一个值传递出去,那么最简单php下拉框数据库的方法用的就可以是js 你的代码中form没有提交表单按钮,那么就是使用js让它充当提交按钮 用到了 下拉选择框的onchange属性
具体写法呢:
form action="xianshi.php" method="post" id="form" !--这里给表单一个id--
fieldsetlegend选择您要查看的日期/legend
pb测量日期/b
select name="time" onchange="fun()" !--这里的给一个onchange事件 也就是说当下拉框的值改变时将触发onchange里面的函数fun()--
?php
while($colum=mysqli_fetch_array($result)){
?
option value="?php echo $colum["time"];?"?php echo $colum["time"];?/option;
?php
}
?
!--下面是js代码 对fun函数进行操作--
script type="text/javascript"
function fun(obj){
var form = document.getElementById("form");//选中你的表单
form.submit(); //执行提交
}
/script
Q2: PHP下拉列表菜单SELECT选定对应项后检索数据库显示数据问题
muban.php页面(前端):
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title临床医学诊断查询/title
script language="javascript"
function getinfo(obj)
{
mbstr=obj.value;
dt="mbstr=" + mbstr;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (this.readyState==4 this.status==200)
{
res= JSON.parse(this.responseText);
document.getElementById("zhengxiang").innerHTML=res[0].YxInfo;
document.getElementById("yijian").innerHTML=res[0].YjInfo;
}
}
xmlhttp.open("POST","mubanexec.php",true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(dt);
return;
}
/script
/head
body
select name="toubu" id="toubu" onchange="getinfo(this)"
option selected="selected"头部/option
option头部正常/option
option脑萎缩/option
option脑萎缩脱髓鞘/option
/select
divtextarea name="zhengxiang" id="zhengxiang"/textarea/div
div/textareatextarea name="yijian" id="yijian"/textarea/div
/body
/html
mubanexec.php页面(后台处理):
?php
header("Content-type: text/html; charset=utf-8");
$instr=$_POST["mbstr"];
$conn=new PDO("mysql:host=localhost;dbname=pacsdata","username","userpwd");
$sth=$conn-prepare("select YxInfo,YjInfo from moban where MbName=?");
$sth-execute(array($instr));
$res=$sth-fetchAll();
echo(json_encode($res,JSON_UNESCAPED_UNICODE));
?
Q3: PHP提交网页之后根据下拉菜单的值更新数据库
$result2 || die("Unavailable selected! \n".mysqli_error($con));这段如果是数据库连接代码的话,那放的位置应该置顶,规范下应该是$result2=mysql_connect("","","") or die(mysql_error());mysql_select(“数据库",$result2);
$query3 = "UPDATE selectTutorial SET count=count+1 WHERE dates='$date_selected' AND time='$time_selected'"; 这个selectTutorial应该是一个表吧,count=count+1;这个是有问题的,你count只是一个字段,没有具体的值,应该换成row2['count']+1;
因为你这代码也不全,没法实测
Q4: php 点击下拉框的值 数据库显示出来的数据根据点击的值而改变
option onselect = 'show(1)'项目一 /option
option onselect = 'show(2)'项目二 /option
option onselect = 'show(3)'项目三 /option
option onselect = 'show(4)'项目四 /option
script
function show( num)
{
//这里写修改显示值的代码, 如果你不想刷新,只能引用jquery中的ajax
}
/script
Q5: 在php中添加一个下拉框,其他的都正确,只是在网页运行.php文件时,下拉框里取不到数据库的值
你这里都没建立数据库链接。
$conn=mysql_connect("localhost","root","password");
mysql_select_db("database",$conn);
mysql_query("set names gb2312");
$query=mysql_query("select * from table");
while($row=mysql_fetch_array($query)){
......
};
php下拉框数据库的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php下拉表单、php下拉框数据库的信息别忘了在本站进行查找喔。






