I have a simple HTML Form as follow (form.html) :
<form id="tips-message-notes" action="notessaved.php" method="post" class="general-form">
<div class="input-wrap">
<input type="text" name="title" value="'.$Title.'"/>
</div><!-- .input-wrap -->
<div class="input-wrap">
<textarea cols="" rows="" name="article" class="myTextEditor">'.$Article.'</textarea>
</div><!-- .input-wrap -->
<div class="button-wrap">
<input type="submit" name="publish" value="Publish" class="submit-btn" />
<input type="submit" name="draft" value="Save Draft" class="draft-btn" />
</div><!-- .button-wrap -->
</form>
when user click submit button, this PHP will process database insertion (database.php) :
<?php
$Title = $_POST['title'];
$Article = $_POST['article'];
$con = mysql_connect("server","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO Table (Title, Article)
VALUES ('$Title', '$Article')");
mysql_close($con);
?>
the problem is.. how to redirect back to form.html after user hit submit button with values on those input and text area submitted before?
please note that text area might have more than 1024 characters. so I don’t think by putting $article on URL and using GET method on form.html is good idea. I hope I can see other technique from you… thanks!
https://www.php.net/manual/en/book.session.php
You need to use the PHP session.
As a very, very basic tutorial:
session_start()at the start of every page before emitting any output._POSTvalues to_SESSION$Articles = htmlspecialchars($_SESSION['Articles']);, etc.This is the only reliable way to carry the data between multiple pages.
Sanitize your inputs to queries. Either use prepared statements with
PDO(ormysqli) or at a bare minimum, runmysql_real_escape_stringon the_POSTinputs to the query first.