Jump to content

Invovling UPDATE statement within a php page


farban

Recommended Posts

I am having a problem when it comes to updating a post. i click edit in my admin panel which brings up the current title and messege of the post. the main problem is that when i make changes to the title and the messege when i submit the changes the post is reverted back to th orginal created state (without the edited changes). i want it so that the changes i make in the form reflect the changes in the database. i think there is something wrong with my update statement in the script

 

ps dont worry about the caching i didnt want my cms to cache files so the script dosent work which is intended.

 

 

 

 

 

 

 

 

 

<?php

include 'library/config.php';

include 'library/opendb.php';

 

if(isset($_GET['page_id']))

{

  $query  = "SELECT page_id, title, messege ".

            "FROM pages ".

            "WHERE page_id = '{$_GET['page_id']}'";

  $result = mysql_query($query) or die('Error : ' . mysql_error());

  list($page_id, $title, $messege) = mysql_fetch_array($result,                                                    MYSQL_NUM);

 

  $messege = htmlspecialchars($messege);

}

else if(isset($_POST['cmdupdate']))

{

  $page_id = $_POST['page_id'];

  $title = $_POST['title'];

  $messege = $_POST['messege'];

 

  if(!get_magic_quotes_gpc())

  {

      $title = addslashes($title);

      $messege = addslashes($messege);

  }

 

  // update the article in the database

  $query = "UPDATE pages ".

            "SET title = '$title', messege = '$messege' ".

            "WHERE page_id = '$page_id'";

  mysql_query($query) or die('Error : ' . mysql_error());

 

  // then remove the cached file

  $cacheDir = dirname(__FILE__) . '/cache/';

  $cacheFile = $cacheDir . '_' . $_GET['page_id'] . '.html';

 

  @unlink($cacheFile);

 

  // and remove the index.html too because the file list

  // is changed

  @unlink($cacheDir . 'index.html');

 

  echo "Article '$title' updated";

 

  // now we will display $title & content

  // so strip out any slashes

  $title  = stripslashes($title);

  $messege = stripslashes($messege);

}

 

include 'library/closedb.php';

?>

<form method="post" action="<?php echo $PHP_SELF;?>">

<input type="hidden" name="page_id" value="<?=$page_id;?>">

<table width="700" border="0" cellpadding="2" cellspacing="1" class="box">

<tr>

<td width="100">Title</td>

<td><input name="title" type="text" class="box" id="title" value="<?=$title;?>"></td>

</tr>

<tr>

<td width="100">Content</td>

<td><textarea name="messege" cols="50" rows="10" class="box" id="messege"><?=$messege;?></textarea></td>

</tr>

<tr>

<td width="100"> </td>

<td> </td>

</tr>

<tr>

<td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Update Article"></td>

</tr>

</table>

<p align="center"><a href="cms-admin.php">Back to admin page</a></p>

</form>

 

Link to comment
Share on other sites

Try adding some print statements throughout your code, such as

 

print "Entering update branch<br>";
...
print "About to execute $query<br>";
...
print "Query succeeded<br>";

 

That will give you a window into what is happening in your code.

Link to comment
Share on other sites

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.