Page 1 of 1

Refresh issues

Posted: Thu Mar 17, 2011 8:12 pm
by vic3685
Hi everyone!

I'm new around here, not sure if this is the right place to ask my question.

I have just designed my first CMS, all by myself, but I'm having some trouble. The thing is, after doing an edit, the admin won't automatically update the information, so it looks like it didn't really do the edit. It edits the content alright, the front-end does show the changes, but I can't get the back-end to automatically refresh. So far, I've only tried with <META HTTP-EQUIV="Pragma" CONTENT="no-cache">, which didn't help.

Could you point me in the right direction?

Thanks in advance!!!

Vicky

Re: Refresh issues

Posted: Thu Mar 17, 2011 10:34 pm
by Weiry
Hi and welcome to DevNetwork :D

Without knowing a little more about the processes of your CMS, its a little difficult to understand what you mean by:
vic3685 wrote:The thing is, after doing an edit, the admin won't automatically update the information, so it looks like it didn't really do the edit
In making the assumption that you have a user who updates something while an admin is looking at a list of pages, which updates automatically (without pressing F5 or refresh button) while looking at that list, your probably looking at an AJAX solution.

Re: Refresh issues

Posted: Fri Mar 18, 2011 4:01 am
by gooney0
Sounds like one of two issues:

#1 what welry said. You have two different users and need to trigger refreshes.

or

#2 You submit the form and are displaying old data.

In the case of #2 this is a problem with your logic. Your script is pulling in the data before it is updated to the DB. You'll either want to update first, or reselect the data if the form was submitted.

If you can clarify the issue we can be more specific.

Re: Refresh issues

Posted: Fri Mar 18, 2011 6:18 pm
by vic3685
Hi guys! Thanks for your answers!

Let me try to describe this a bit better. This is one of many examples of the same issue I have:

On the admin side, say I create a new item in my CMS. I fill out a form with all the details and press save. It goes ok, I have a "Everything went OK" page, and from there I click on the link to the control panel and it doesn't show the new item. If I click on refresh, it does.

What I want is to avoid that refresh. Now, that link I click on is a regular link, not a "Back" button or anything, and I have already used the no-cache thing. According to the control panel's code, it should pull the data from the database right away.

So I would say it's gooney0's issue #2, but I don't see where I made the mistake :-S

Let me know if you need more specific info. Thank you!!!

Re: Refresh issues

Posted: Fri Mar 18, 2011 6:26 pm
by John Cartwright
Post yer code :wink:

Re: Refresh issues

Posted: Mon Mar 21, 2011 6:22 pm
by vic3685
It really is a lot of code... I'm going to use the simplest of the codes, and just take the example of a text edit function.

The code is as follows:
<?php
$admin_root = "";
$root = "../";
require_once($root."includes/functions.php");
require_once($root."includes/connect.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title>Administración: La empresa</title>
<link type="text/css" href="<?php echo $admin_root; ?>admin.css" rel="stylesheet" />

<script type="text/javascript" src="<?php echo $root;?>scripts/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="<?php echo $root;?>scripts/jquery-ui-1.8.6.custom.min.js"></script>

<!-- //CKEditor -->
<script type="text/javascript" src="<?php echo $root;?>/scripts/ckeditor/ckeditor.js"></script>
</head>

<body>
<div id="container">
<?php include("includes/header.php"); //HEADER ?>

<div id="content" style="color:">

<?php

#/ Form to displayed
function defaultForm()
{

//get existing text
$empresa = get_datos_empresa();
$empresa_txt = mysql_fetch_array($empresa);
echo "<script type='text/javascript'> CKEDITOR.replace( 'empresa' );</script>";

global $empresa_txt;
echo "<form method=\"post\" enctype=\"multipart/form-data\" id='empresa_form'>\n";
echo "<h1>La empresa: </h1>";
echo "<textarea name='empresa' rows='10' cols='90' id='empresa'>".$empresa_txt['contenido']."</textarea><br />";
echo "<input name=\"Submit\" type=\"submit\" value=\"Submit\">\n";
echo "<input name=\"filter\" type=\"hidden\" value=\"processForm\">\n"; ##/ hidden value points the switch to processing
echo "</form>";

echo "<script type='text/javascript'>
CKEDITOR.replace( 'empresa' );</script>";
return;

}
#/ End of defaultForm


##/ Function that displays forms and is called by default
function processForm() {
global $connection;
global $empresa_txt;

$message = "";

//RECEIVE VALUES

//empresa
$emp_contenido = mysql_prep($_POST['empresa']);

//UPLOAD VALUES: empresa
$query = "UPDATE empresa SET
contenido = '{$emp_contenido}'
WHERE tipo = 'empresa' ";
$result = mysql_query($query, $connection);
if (mysql_affected_rows() == 1) {
// Success
$message .= "It succeeded." ;
} elseif (!mysql_error() | mysql_error() == "") {
// No change was requested
$no = 1;
}
else {
// Failed
$message .= "The text could not be updated.";
$message .= "<br />". mysql_error();
}




if ($message == "") {$message = "No change was requested.";}
$message .= "<br />". "<a href='".$menu_root."edit_empresa.php'>Back</a>";

echo $message;
return;
}
#/ End of processForm


##/ This object handles which function the application should call
switch($_POST[filter]) {
case "processForm":
processForm($cat_cod, $cat_txt, $cat_type, $connection);
break;
default:
defaultForm($opciones_cat);
break;
}
#/ End of Handling

?>


</div>


<?php include("includes/footer.php"); ?>


</div>
</body>
</html>

<?php
// 5. Close connection
mysql_close($connection);
?>