title: Update post from database
body: <p>I'm trying to get my post to update just in case I make a mistake the first time around posting an article to my website.</p>
  
  <p>Not sure what I'm doing wrong here.</p>
  
  <p>Here is my update code:</p>
  
  <pre><code>    &lt;div class="row"&gt;
          &lt;?php
  $post_title = "";
  $description = "";
  $id = $_GET['id'];
  
  $result = mysql_query("SELECT title, description FROM htp_news WHERE id='$id'");
  
  $post_title     = mysql_result($result,0,"title");
  $description    = mysql_result($result,0,"description");
  
  ?&gt;
  
      &lt;div class="row"&gt;
  
  &lt;form method="post" action="update-news.php"&gt;
  &lt;input type="hidden" name="ud_id" style="width: 100%" value="&lt;? echo "$id"; ?&gt;"&gt;
  
  &lt;div class="grid_12 botspacer60"&gt;
  
  
  Title: &lt;input type="text" name="ud_title" value="&lt;?php echo "$post_title"; ?&gt;"&gt;
  &lt;br /&gt;&lt;br /&gt;
  
  News Details:&lt;br /&gt;
  &lt;textarea id="tiny_mce" name="ud_description" rows="8"&gt;&lt;?php echo "$description"; ?&gt;&lt;/textarea&gt;
  
  &lt;/div&gt;
  
  
  &lt;div class="grid_12"&gt;
  
      &lt;input type="submit" value="Update"&gt;
      &lt;input type="button" value="Cancel" onclick="window.location = '/admin'"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  
  
  &lt;/div&gt;
  </code></pre>
  
  <p>And here is my action page:</p>
  
  <pre><code>&lt;?php
  include($_SERVER['DOCUMENT_ROOT'] . "/includes/database.php");
  
  $ud_id          = $_POST['ud_id'];
  $ud_title       = $_POST['ud_title'];
  $ud_description = $_POST['ud_description'];
  
  // Insert record into database by executing the following query:
  $query="UPDATE htp_news SET title='$ud_title', description='$ud_description' "."WHERE id='$ud_id'";
  
  mysql_query($query);
  
  
  echo "The post has been updated.&lt;br /&gt;
  &lt;a href='edit-delete-news.php'&gt;Update another position.&lt;/a&gt;&lt;br /&gt;";
  
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>I appreciate any guidance on the matter.</p>