I have a text area page which is launched from the previous page:
$message = $_POST['editPost'];
header("location:editPost.php?msg=$message");
The editPost.php retrieves this and fills the text area like so:
echo "<form action='index.php' method='post'>
Your Post:<br/>
<textarea name='comments' cols='100' rows='100'>".$_GET["msg"]."</textarea>
<br/>
<input type=submit value='submit'>
</FORM>";
The problem I’m getting is not all the data of ‘msg’ seems to get passed across, or the message gets cut of at the point where it reaches a quotation mark e.g. ‘
The text I want it to fill the textarea with this text:
So this is my second blog post for this assignment, I’ve progressed a bit since my previous post
however it only add this to the text area this:
So this is my second blog post for this assignment, I
As I say it seems to not contain any more of the string after the quotation mark is reached. Is there anyway around this so I can pass the whole message across?
EDIT
I might add, I’m aware a more simple solution would be to retrieve the message again from the MySQL database as that’s what I’m using, but I’m just intrigued as to how this works.
if(isset($_POST['edit'])) {
//$_SESSION['postToEdit'] = $_POST['editPost'];
$message = htmlentities($_POST['editPost'], ENT_QUOTES);
header("location:editPost.php?msg=$message");
That is what I do with the data once it is posted from this form:
foreach($posts as $postid=>$post)
{
echo '<div class="blogPosts">'.$post;
if(isset($_SESSION['username'])) {
if($_SESSION['isAdmin'] == "true") {
echo "<br/><br/><form name='adminTools' action='index.php' method='post'>
<input type='hidden' name='editPost' value='$post'>
<input type='submit' value='Edit' name='edit'/>
<input type='hidden' name='deletePost' value='$postid'>
<input type='submit' value='Delete' name='delete' /></form>
</div>";
I think I get it.
header("location:editPost.php?msg=$message");doesn’t smells good.If you simply want to fix the problem use http://php.net/manual/en/function.urlencode.php and when getting the value http://www.php.net/manual/en/function.urldecode.php
You’re getting a post request and then forwarding it using header location. That’s definitely a poor way to do it. The problem probably is taking place when you pass the parameter as a query string on
?msg=$messageSince MVC and alike applications (n-layered apps) is the standard now. You should not do that spaghetti code, mixing html and php and using header as your FrontController dispatcher.
I’d suggest you to use for example, the SLIM framework. If you do not want to learn this. You should at least follow the standards described here.
E.g.:
In short, create a FrontController file that will map to the desired actions (controllers) according to the request without using
header()to execute specific actions (the exception is only if actually the headers are needed, in fact).