html页面输入数据,result2.php 插入mysql数据 ,提示result2最后一行提示parse 错误。谢谢回复!源代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body><form action="result2.php" method="post" target="_self">
日期:<INPUT TYPE="TEXT" NAME="date" SIZE="10">
金额:<INPUT TYPE="TEXT" NAME="money" SIZE="10">
类别: <SELECT NAME="sort" >
<OPTION VALUE="生活">生活
<OPTION VALUE="布">布
<OPTION VALUE="办公">办公
</SELECT> 备注:<INPUT TYPE="TEXT" NAME="re" SIZE="30">
<INPUT TYPE="SUBMIT" VALUE="添加">
</form></body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body><?php
$date1=trim($_POST['date']);
$money=trim($_POST['money']);
$sort=trim($_POST['sort']);
$re=trim($_POST['re']);@ $db = new mysqli('localhost', 'root', '', 'company');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "insert into diary (date,money,sort,re) values ($date1,$money,$sort,$re);
$result = $db->query($query);
$result->free();
$db->close();
?>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body><form action="result2.php" method="post" target="_self">
日期:<INPUT TYPE="TEXT" NAME="date" SIZE="10">
金额:<INPUT TYPE="TEXT" NAME="money" SIZE="10">
类别: <SELECT NAME="sort" >
<OPTION VALUE="生活">生活
<OPTION VALUE="布">布
<OPTION VALUE="办公">办公
</SELECT> 备注:<INPUT TYPE="TEXT" NAME="re" SIZE="30">
<INPUT TYPE="SUBMIT" VALUE="添加">
</form></body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body><?php
$date1=trim($_POST['date']);
$money=trim($_POST['money']);
$sort=trim($_POST['sort']);
$re=trim($_POST['re']);@ $db = new mysqli('localhost', 'root', '', 'company');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "insert into diary (date,money,sort,re) values ($date1,$money,$sort,$re);
$result = $db->query($query);
$result->free();
$db->close();
?>
</body>
</html>
$query = "insert into diary (date,money,sort,re) values ('".$date1."','".$money>'",'".$sort."','".$re."')";这样试试
$result = $db->query($query);
if ($result) {
echo $db->affected_rows." 插入成功.";
} else {
echo "插入失败";
}
$db->close();表diary:
字段 类型 整理 属性 空 默认 额外 操作
ID int(11) 否 无 auto_increment
data date 否 无
money float 否 无
sort char(10) latin1_swedish_ci 否 无
re char(200) latin1_swedish_ci 否 无
谢谢大家热心回复。