Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/161510-solved-updating-a-page/
Share on other sites

		$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';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.