php对数据库的操作有关问题!很急

WBOY
Release: 2016-06-13 12:01:08
Original
912 people have browsed it

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 "<script>alert('数据添加成功!');window.location.href='zhangdan.php';</script>";
}else{
echo "<script>alert('数据添加失败!');history.back();window.location.href='doAdd.php';</script>";
}

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 "<script>alert('编辑数据成功!');history.back();window.location.href='zhangdan.php?id=$id';</script>";
}else{
echo "<script>alert('编辑数据失败!');history.back();window.location.href='zhangdan.php?id=$id';</script>";
}
?>

------解决方案--------------------
$sql=mysql_query("insert into tb_pay(article,type,money,remark,date)values('$article','$type','$money','$remark','$date')") or die(mysql_error());

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template