When I submit a form to a PHP_SELF page via POST method, The text get's inserted into the table again on every refresh. How do I fix this and prevent my textarea from being empty before insertion?
echo "<form action=<?php echo $_SERVER['PHP_SELF']; method='post'>";
echo "<textarea name='msg' placeholder='Type message here' required='required' style='width:100%;min-height:60px;min-height:60px;'></textarea>";
echo "<button>Send</button>";
echo "</form>";
And here is my PHP code to insert the text into the table 'msg'.
if(isset($_POST['msg'])&!empty($_POST['msg']))
{
$message=$_POST['msg'];
$message=$conn->quote($message);
$sql="INSERT INTO msg(msg.to,msg.from,msg) VALUES('".$_SESSION["tousermessage"]."','".$_SESSION["username"]."',$message)";
$ex=$conn->prepare($sql);
$ex->execute();
unset($_POST['msg']);
}