php对数据库的操作有关问题!很急
时间:2021-07-01 10:21:17
帮助过:7人阅读
php对数据库的操作问题!很急!
对数据库的添加为什么老是显示添加失败?????
error_reporting(E_ALL & ~E_NOTICE);
$conn=mysql_connect("localhost","root","root") or die("数据库服务器连接错误".mysql_error());
mysql_select_db("bill",$conn) or die("数据库访问错误".mysql_error());
mysql_query("set names gb2312");
$article=$_POST['txt_article'];
$type=$_POST['txt_type'];
$money=$_POST['txt_money'];
$remark=$_POST['txt_remark'];
$date=date("Y-m-d");
$sql=mysql_query("insert into tb_pay(article,type,money,remark,date)values('$article','$type','$money','$remark','$date')");
if($sql){
echo "";
}else{
echo "";
}
mysql_free_result($sql);
mysql_close($conn);
?>
对数据库的修改为什么老是显示添加失败?????
error_reporting(E_ALL & ~E_NOTICE);
$conn=mysql_connect("localhost","root","root") or die("数据库服务器连接错误".mysql_error());
mysql_select_db("bill",$conn) or die("数据库访问错误".mysql_error());
mysql_query("set names gb2312");
$date=date("Y-m-d ");
$article=$_POST[article];
$type=$_POST[type];
$money=$_POST[money];
$remark=$_POST[remark];
$id=$_POST[id];
$sql=mysql_query("update tb_pay set date='$date',article='$article',type='$type',money='$money',remark='$remark' where id=$id");
if($sql){
echo "";
}else{
echo "";
}
?>
------解决方案--------------------
$sql=mysql_query("insert into tb_pay(article,type,money,remark,date)values('$article','$type','$money','$remark','$date')") or die(mysql_error());