scarhand Posted July 2, 2007 Share Posted July 2, 2007 I'm trying to set up a simple preview-type thing for my very first blog script (im new to php and mysql). First off, heres my code for the update (place to post a new article) page (excluding the includes to connect to the database): function postNews() { global $db; $title = $_POST['title']; $newstext = $_POST['newstext']; $query = "INSERT INTO news (title, newstext) VALUES ('$title', '$newstext')"; mysql_query($query) or die('Error, MySQL query failed'); echo "<div class=\"evenbg\" style=\"padding: 10px;\"> \n"; echo "Article <b>'$title'</b> has been added.<br> \n"; echo "Go to the <b><a href=\"index.php\">index</a></b> to check it out.<br> \n"; echo "</div> \n \n"; } function postPreview() { $title = $_POST['title']; $newstext = $_POST['newstext']; echo "<div class=\"oddbg\"> \n"; echo "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"0\" border=\"0\"> \n"; echo "<tr> \n"; echo "<td><font class=\"newstitle\">$title</font></td> \n"; echo "</tr> \n"; echo "</table> \n"; echo "</div> \n"; echo "<div class=\"evenbg\"> \n"; echo "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"0\" border=\"0\"> \n"; echo "<tr> \n"; echo "<td colspan=\"2\" class=\"newsbox\">$newstext</td> \n"; echo "</tr> \n"; echo "</table> \n"; echo "</div> \n"; } if (isset($_POST['save'])) { if (empty($_POST['title'])) { echo "<div class=\"errordiv\"><b>Error:</b> You must enter a title for the new article.</div>"; } elseif (empty($_POST['newstext'])) { echo "<div class=\"errordiv\"><b>Error:</b> You must enter some content for the new article.</div>"; } else { postNews(); } } elseif (isset($_POST['preview'])) { if (empty($_POST['title'])) { echo "<div class=\"errordiv\"><b>Error:</b> You must enter a title for the new article.</div>"; } elseif (empty($_POST['newstext'])) { echo "<div class=\"errordiv\"><b>Error:</b> You must enter some content for the new article.</div>"; } else { postPreview(); } } echo "<form method=\"post\">"; echo "<div class=\"oddbg\">"; echo "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"0\" align=\"center\" border=\"0\">"; echo " <tr>"; echo " <td width=\"70\" align=\"right\"><b>Title:</b></td>"; echo " <td>"; echo " <input name=\"title\" type=\"text\" id=\"title\" maxlength=\"50\" style=\"width: 100%\">"; echo " </td>"; echo " </tr>"; echo "</table>"; echo "</div>"; echo "<div class=\"evenbg\">"; echo "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"0\" align=\"center\" border=\"0\">"; echo " <tr>"; echo " <td width=\"70\" valign=\"top\" align=\"right\"><b>Content:</b></td>"; echo " <td>"; echo " <textarea name=\"newstext\" rows=\"18\" id=\"newstext\" style=\"width: 100%\">"; echo " </textarea>"; echo " </td>"; echo " </tr>"; echo "</table>"; echo "</div>"; echo "<br>"; echo "<input name=\"save\" type=\"submit\" id=\"save\" value=\"Add the Article\">"; echo " "; echo "<input name=\"preview\" type=\"submit\" id=\"preview\" value=\"Preview the Article\">"; echo "</form>"; Now I have tried making the value for the textarea to be this: value="<?php $newstext ?>" But it still gets removed after being posted. Any help would be greatly appreciated as I've been searching google for a solution for the past hour. Link to comment https://forums.phpfreaks.com/topic/58050-solved-make-forms-keep-data-after-being-posted/ Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Share Posted July 2, 2007 Try this: value="<?php echo $newstext; ?>" Link to comment https://forums.phpfreaks.com/topic/58050-solved-make-forms-keep-data-after-being-posted/#findComment-287798 Share on other sites More sharing options...
scarhand Posted July 2, 2007 Author Share Posted July 2, 2007 Try this: value="<?php echo $newstext; ?>" That causes the title input form to have "<?php echo ; ?>" in it, and the newstext textarea form is only filled with 4 spaces. Link to comment https://forums.phpfreaks.com/topic/58050-solved-make-forms-keep-data-after-being-posted/#findComment-287806 Share on other sites More sharing options...
redarrow Posted July 2, 2007 Share Posted July 2, 2007 try session's ok <?php session_start();// << must be set to top off page ok. $_SESSION['news']=$news; $_SESSION['titke=$title; ?> value=<?echo $_SESSION['news'];?> value=<?echo $_SESSION['title'];?> Link to comment https://forums.phpfreaks.com/topic/58050-solved-make-forms-keep-data-after-being-posted/#findComment-287812 Share on other sites More sharing options...
scarhand Posted July 2, 2007 Author Share Posted July 2, 2007 try session's ok <?php session_start();// << must be set to top off page ok. $_SESSION['news']=$news; $_SESSION['titke=$title; ?> value=<?echo $_SESSION['news'];?> value=<?echo $_SESSION['title'];?> did the trick, thanks! Link to comment https://forums.phpfreaks.com/topic/58050-solved-make-forms-keep-data-after-being-posted/#findComment-287829 Share on other sites More sharing options...
redarrow Posted July 2, 2007 Share Posted July 2, 2007 if this is solved please hit solved cheers. Link to comment https://forums.phpfreaks.com/topic/58050-solved-make-forms-keep-data-after-being-posted/#findComment-287837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.