Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp sql, form resubmits on page load
    primarykey
    data
    text
    <p>Neglecting the obvious security flaws of mysql and nor sql escape strings, does anybody know why my sql tables are getting filled up with empty <code>msgs</code> on page reload. Every sinngle time the page reloads a form submits. I'm confused as to why this is happening, and how do i stop it?</p> <pre><code> &lt;?php ob_start(); session_start(); $con = mysql_connect("localhost","username","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } $dates = date('Y-m-d H:i:s'); $uid = $_SESSION['user_id']; $msg_id = (int) $_GET['msg_id']; mysql_select_db("db_table", $con); $result = mysql_query("SELECT users.first_name, users.last_name , intro.intro, intro.outro FROM intro INNER JOIN users ON intro.user_id = users.user_id WHERE intro.message_id = {$msg_id}"); while($row = mysql_fetch_array($result)) { echo "&lt;div id=\"start\"&gt;&lt;div class=\"namedate\"&gt;&lt;h1&gt;". $row['first_name'] ." ". $row['last_name'] . "&lt;/h1&gt;&lt;h2&gt;test&lt;/h2&gt;&lt;/div&gt;&lt;div id=\"holdmsg\"&gt;&lt;div class=\"cent\"&gt;&lt;strong&gt;" . $row['intro'] . "&lt;/strong&gt;&lt;br&gt;&lt;i&gt;" . $row['outro'] ."&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; " ; } </code></pre> <p>PART RELEVANT TO THE FORM is this part and also the $_GET, at the top of the page. </p> <pre><code>&lt;form action="" method="post"&gt; &lt;?php $sql="INSERT INTO messages (user_id, intro_id , msg, date ) VALUES (('$uid'), {$msg_id} ,'$_POST[msg]', ('$dates'))"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?&gt; &lt;textarea rows="2"style="float:left" name="msg" type="text"placeholder="Elaborate on your idea..."&gt;&lt;/textarea&gt; &lt;input id="togz2" style="float:right; "type="submit" value="SUBMIT" name="submit" class="butts"&gt; &lt;/div&gt;&lt;/div&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