Home  >  Article  >  Database  >  insert-通过Php程序 像数据库插入内容时。在页面提交之后,mysql会有两个相同的数据 只有id不同

insert-通过Php程序 像数据库插入内容时。在页面提交之后,mysql会有两个相同的数据 只有id不同

WBOY
WBOYOriginal
2016-06-20 08:42:141419browse

mysqlinsertphp

if($action == 'insert'){ //接收数据 $title = empty($_POST['subject']) ? '' : $_POST['subject']; $content = empty($_POST['content']) ? '' : $_POST['content']; $user_id = $_SESSION['myuser']['id']; $create_ad = time(); $summary = empty($_POST['summary']) ? '' : $_POST['summary']; $category_id = empty($_POST['category_id']) ? '' : $_POST['category_id']; $cover = empty($_POST['cover']) ? 'mr.jpg' : $_POST['cover']; $state = empty($_POST['submit']) ? '' : $_POST['submit']; $is_delete = 0; $tags = ''; //验证 if($category_id == '' || $title == '' || $content = '' || $summary == ''){ header('refresh : 2 ; url = article.php?a=add'); echo '输入的信息有误,请重新输入'; exit; } //入库 $sql = "INSERT INTO tn_article VALUES(null, '$title','$content', $user_id, $create_ad, '$summary', $category_id, '$cover', '$state', '$is_delete', '$tags')"; //获取页面 if($dao ->query($sql)){ header('location:article.php?a=list'); exit; } else{ header('refresh : 2; url = article.php?a=add'); echo '添加失败'; exit; }}

Statement:
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