Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy php input blank value or duplicate values in one form if submit another form
    primarykey
    data
    text
    <p>I am encountering a strange phenomena: When I submit a form in my code, then beside doing what is there in that form, it looks like it also trigger the comment form. So when the page is reloading, I get some blank comments or duplicate comments. In my code I have several forms with submit, and one of that is the form for input comment:</p> <pre><code>&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt; &lt;input type="hidden" name="a" value="&lt;?php echo $_GET['id'] ?&gt;"&gt; &lt;input type="hidden" name="b" value="&lt;?php echo $_SERVER['REMOTE_ADDR'] ?&gt;"&gt; &lt;input type="text" name="c" value="Name"&gt;&lt;br&gt; &lt;textarea name="d"&gt; &lt;/textarea&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>Could any of you point out for me where it gets wrong?</p> <p>As requested, I post the whole (updated) code here:</p> <pre><code>&lt;h3&gt;Comments&lt;/h3&gt; &lt;!-- &lt;p&gt;Put your comments here: &lt;/p&gt; --&gt; &lt;?php //a: commenters $i = addslashes($_POST['a']); $ip = addslashes($_POST['b']); $a = addslashes($_POST['c']); $b = addslashes($_POST['d']); if(isset($_POST['form1'])){ if(isset($i) &amp; isset($ip) &amp; isset($a) &amp; isset($b)) { $connector= new DbConnector(); $r = mysql_query("SELECT COUNT(*) FROM `databasename`.`ban` WHERE ip=$ip"); //Check if banned $r = mysql_fetch_array($r); if(!$r[0]) //Phew, not banned { // echo "a: ".$a." b: ".$b." ip: ".$ip." i: ".$i.""; $Date4=date('Y-m-d H:i:s'); if(mysql_query("INSERT INTO `databasename`.`Comments` VALUES ('$a', '$b', '$ip', '$Date4')")) { ?&gt; &lt;script type="text/javascript"&gt; window.location="/index.php?id=".&lt;?php echo $i; ?&gt;; &lt;/script&gt; &lt;?php } else echo "Error, in mysql query"; } else echo "Error, You are banned."; } } $x = mysql_query("SELECT * FROM `databasename`.`Comments` ORDER BY i DESC "); while($r = mysql_fetch_object($x)) echo "&lt;div class='c'&gt;".$r-&gt;a."&lt;p&gt;".$r-&gt;b."&lt;/p&gt; &lt;/div&gt;"; ?&gt; &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt; &lt;input type="hidden" name="a" value="&lt;?php echo $_GET['id'] ?&gt;"&gt; &lt;input type="hidden" name="b" value="&lt;?php echo $_SERVER['REMOTE_ADDR'] ?&gt;"&gt; &lt;input type="text" name="c" value="Name"&gt;&lt;br&gt; &lt;textarea name="d"&gt; &lt;/textarea&gt; &lt;input type="submit" name="form1" /&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload