dongpa5207 2014-01-21 10:44
浏览 20
已采纳

成功存储在db中时出现php错误消息

I have code for store some data to data base. Before edit its success store database but problem is when I am refresh duplicate data.

I am edited and worked without any problem but when I press submit and store data to db I get an message error > why ?

this is form code (index.php)

<html>
<head>
<title>Proposals Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="columns.css" />
</head>

<body bgcolor="#3AA0BC">
<table border="5">
<form action="enterinfo.php" method="post"><br /><br />
<center> FirstName :<br /><input type="text" name="Name" id="Name" size="25"><br /><br/>
Title :<br />&nbsp;<textarea name="title" id="title" size="50"></textarea></center>
<p><th><input type=submit value="OK" name="submit" id="submit"class="buttStyle"></th</p>
</form>

<form action="view.php" method="post">
<p><th><input type=submit value="عرض المواظيع" class="buttStyle"></th></p></form>
<form action="addcomment.php" method="post">
<p><th><input type=submit value="اضافة تعليق" class="buttStyle"></th></p>
</form>
</body>
</html>

and enter code is (enterinfo.php)

<?php
include ("connect.php");
$Name=isset($_POST['Name']) ?
$_POST['Name'] : '';
$title=isset($_POST['title']) ?
$_POST['title'] : '';
$submit = isset($_POST['submit']) ? 
$_POST['submit'] : '';

if(isset($_POST['submit']))
{
 if($Name && $title)
 {
  $result=mysql_query("INSERT INTO subject(S_Id,Name,title)
                                     VALUES(NULL, '$Name', '$title')");  
  header('Location: enterinfo.php');

 }
}
 if($result)
{
echo "Successful";
echo "<BR>";
}
else
{
echo "error";
}
?>
  • 写回答

5条回答 默认 最新

  • duanlvxi8652 2014-01-21 10:52
    关注

    set a variable in your url after executing your query(i have used re) and check at the top of your page if re exists then echo your message based on re value and exit.
    Change your enterinfo.php like below code
    Try this:

      if(isset($_REQUEST['re'])){   
        $message = $_REQUEST['re'] == 'success' ? "Sucessfully inserted" : "can not  inserted";   
        echo $message;
        exit();
      }
    
    
    
    
    include ("connect.php");
    $Name=isset($_POST['Name']) ?
    $_POST['Name'] : '';
    $title=isset($_POST['title']) ?
    $_POST['title'] : '';
    $submit = isset($_POST['submit']) ? 
    $_POST['submit'] : '';
    
     if(isset($_POST['submit']) )
        {
         if($Name && $title)
         {
          $result=mysql_query("INSERT INTO subject(Name,title)
                                             VALUES('$Name', '$title')");  
         if($result){
           header('Location: enterinfo.php?re=success');
          }
          else{
            header('Location: enterinfo.php?re=fails');
           }   
         }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?