Onloac Posted June 9, 2009 Share Posted June 9, 2009 Hello, I'm hoping you guys can help me find a solution to my problem. I use a PHP page to add categories to my database. I have my page layout as followed: Add category form list of all categories in database Once I add a category a message appears above the form letting me know that the category has been added. The thing that bothers me is the newly added category isn't showing up on the category list UNTIL i refresh the page. What I want to know is why its not being display right away and how I can have it do so. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/161510-solved-updating-a-page/ Share on other sites More sharing options...
Maq Posted June 9, 2009 Share Posted June 9, 2009 Can you post the relevant code please? Quote Link to comment https://forums.phpfreaks.com/topic/161510-solved-updating-a-page/#findComment-852311 Share on other sites More sharing options...
scvinodkumar Posted June 9, 2009 Share Posted June 9, 2009 are you using ajax to store the category in the database? Quote Link to comment https://forums.phpfreaks.com/topic/161510-solved-updating-a-page/#findComment-852312 Share on other sites More sharing options...
Onloac Posted June 9, 2009 Author Share Posted June 9, 2009 $TITLE = "Modify Categories"; require 'header.php'; echo "<span class=\"htxt\">Modify Categories</span><br />"; echo "Here you can Add/Edit/Delete categories found within your database.<br /><br />"; $result = $db->query("SELECT * FROM articles_cat ORDER BY category") or die(mysql_error()); ?> <table align="center" border="0" WIDTH="100%" cellpadding="3" cellspacing="1"> <?PHP $mod = $_GET['mod']; switch($mod) { case "add": $addcat = mysql_escape_string ($_POST["addcat"]); if ($addcat) { $db->query("INSERT INTO articles_cat (cid, category) VALUES('', '$addcat') ") or die(mysql_error()); } ?> <tr><td colspan="4" align="center" background="navbg.gif" class="nav"><b>Category Added</b></td></tr> <tr><td colspan="4" align="center" bgcolor="#E6E6E6">You have successfully added <b><?php echo $_POST['addcat']; ?></b> to your category list.<br><br></td></tr> <?php break; case "del": $cid = $_GET["cid"]; $db->query("DELETE FROM articles_cat WHERE cid='$cid'") or die(mysql_error()); ?> <tr><td colspan="4" align="center" background="navbg.gif" class="nav"><b>Category Deleted</b></td></tr> <tr><td colspan="4" align="center" bgcolor="#E6E6E6">You have successfully deleted the category.<br><br></td></tr> <?php break; } ?> <form action="categories.php?mod=add" method="post"> <tr><td colspan="4" height="23" background="navbg.gif" colspan="2" class="nav" align="center">Add New Category</td></tr> <tr><td colspan="4" bgcolor="#E6E6E6" align="center">Category Name: <input type="text" name="addcat" size="30"><input type="submit" value="Submit"></td></tr> </form> <tr><td width="30" height="23" align="center" background="navbg.gif" class="nav"><b>#</b></td> <td background="navbg.gif" height="23" class="nav"><b>Category</b></td> <td height="23" background="navbg.gif" align="center" class="nav"><b>Modify</b></td> <td background="navbg.gif" height="23" align="center" class="nav"><b>Delete</b></td> </tr> <?PHP while($row = $db->fetch_array( $result )) { echo "<tr><td bgcolor=\"#E6E6E6\" align=\"center\">".$row['cid']."</td><td bgcolor=\"#E6E6E6\">".$row['category']."</td><td align=\"center\" bgcolor=\"#E6E6E6\"><a href=\"?c=e&cid=".$row['cid']."\"><img border=\"0\" src=\"edit.gif\" alt=\"Edit Category\"></a></td><td align=\"center\" bgcolor=\"#E6E6E6\"><a href=\"?mod=del&cid=".$row['cid']."\" onclick=\"return confirm('Are you sure you want to delete this category?');\"><img border=\"0\" src=\"delete.gif\" alt=\"Delete Category\"></a></td></tr>"; } echo "<tr><td height=\"23\" background=\"navbg.gif\" colspan=\"4\"></td></tr>"; echo "</table>"; require 'footer.php'; Quote Link to comment https://forums.phpfreaks.com/topic/161510-solved-updating-a-page/#findComment-852315 Share on other sites More sharing options...
scvinodkumar Posted June 9, 2009 Share Posted June 9, 2009 just add this line $result = $db->query("SELECT * FROM articles_cat ORDER BY category") or die(mysql_error()); before the while loop while($row = $db->fetch_array( $result )) { Quote Link to comment https://forums.phpfreaks.com/topic/161510-solved-updating-a-page/#findComment-852320 Share on other sites More sharing options...
Onloac Posted June 9, 2009 Author Share Posted June 9, 2009 Worked like a charm. thx! Quote Link to comment https://forums.phpfreaks.com/topic/161510-solved-updating-a-page/#findComment-852325 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.