猿问

无法添加数据到数据库

<html>
<head><title>员工信息表</title></head>
<center>
<h1>员工信息表</h1>
<form method="POST"  action="add_html.php">
id :<input type="text" name="txtid"><br>
姓名 :<input type="text" name="txtname"><br>
所属部门:<input type="text" name="txtdept"><br>
出生日期:<input type="text" name="txtbirth"><br>
入职时间:<input type="text" name="txttime">
</form>
<input type="submit" name="ok" value="提交">
<input type="reset"  value="重填"></center>
</html>

<?php
include "mysqlconnect.php";
if(isset($_POST['ok']))
{
	$id=$_POST['txtid'];
	$name=$_POST['txtname'];
	$dept=$_POST['txtdept'];
	$birth=$_POST['txtbirth'];
	$time=$_POST['txttime'];
	$sql="insert into zy(id ,姓名,所属部门,出生日期,入职时间) values($id,'$name','$dept',$birth,$time)";
	
	$res=mysql_query($sql);
	
	
	if($res)
	{
		echo "<script> alert('数据库添加成功');</script>";
		echo "<script>window.location.href='showList.php'</script>";
	}
	else
	{
		echo "<script> alert('添加失败');</script>";
	}
}

mysql_close($myline);
?>


萧0817xxlqw
浏览 2663回答 10
10回答

大大大大鹿眸

<input type="submit" name="ok" value="提交">把这段的value=“ok”才行,这样他的值才是okif(isset($_POST['ok']))你这段才会执行,如果你不改value你应该写成if(isset($_POST['提交']))才是

灬紫羽

小伙子啊,你的表单的submit都不在表单里面,表单怎么发送数据到add_html.php页面啊

mooc用户18273

bug好多啊。。。。

wlaiyj520

submit提交在表单外面怎么post获得name

萧0817xxlqw

,,,

hxh_kylin

字段名是否是汉字?出生日期,入职时间的类型应该不是数值吧,也得加引号

晚安sp

姓名,所属部门,出生日期,入职时间) 这是什么?汉字??。。。。。。改成英文或者拼音试试
随时随地看视频慕课网APP
我要回答