Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. // articles.php
  2. // Design the form based on the action the user selected.
  3. <?php
  4.     $action = $_GET["action"];
  5.     $target = $_GET["target"];
  6.  
  7.     if ($action == "Edit") {
  8.         $query = "SELECT * FROM Articles WHERE ArticleTitle = '".$target."'";
  9.         $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
  10.         if (mysql_num_rows($result) > 0) {
  11.             list($ArticleID, $Category, $ArticleDate, $ArticleTitle, $ArticleContent) = mysql_fetch_row($result);
  12.             $cat = $Category;
  13.             $title = $ArticleTitle;
  14.             $content = $ArticleContent;
  15.         }
  16.        
  17.         $query = "SELECT CategoryName FROM Categories WHERE DeletedYN = 'No'";
  18.         $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
  19.  
  20.         echo "<form name=\"editarticle\" method=\"post\" action=\"articlework.php\">".
  21.             "<table>".
  22.             "<tr>".
  23.             "<td>Article Title<br /><input type=\"text\" name=\"article_title\" value=\"".$title."\" style=\"width: 300px;\" /></td>".
  24.             "<td>Category<br />".
  25.             "<select name=\"article_cat\">".
  26.             "<option selected value=\"".$cat."\">".$cat."</option>";
  27.             if (mysql_num_rows($result) > 0) {
  28.                 while($row = mysql_fetch_array($result)) {
  29.                     echo "<option value=\"".$row['CategoryName']."\">".$row['CategoryName']."</option>";
  30.                 }
  31.             }
  32.         echo "</tr>".
  33.             "<tr>".
  34.             "<td colspan=\"2\"><textarea id=\"article_content\" name=\"article_content\" rows=\"15\" cols=\"80\" style=\"width: 80%;\">".$content."</textarea>".
  35.             "<tr>".
  36.             "</table>".
  37.             "<div class=\"RightAlign\"><input type=\"submit\" name=\"btnSubmit\" value=\"Update Article\" /></div>".
  38.             "</form>";
  39.     }
  40. ?>
  41.  
  42. //articlework.php
  43. // Update the article to save the changes made by the user.
  44. <?php
  45.     $title = $_GET["article_title"];
  46.     $cat = $_GET["article_cat"];
  47.     $content = $_GET["article_content"];
  48.    
  49.     // Set database server access variables:
  50.     $host = "localhost";
  51.     $user = "root";
  52.     $pass = "root";
  53.     $db = "logansarchive";
  54.  
  55.     // Open connection
  56.     $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
  57.    
  58.     // Select database
  59.     mysql_select_db($db) or die ("Unable to select database!");
  60.    
  61.     $query = "UPDATE Articles ".
  62.         "SET ArticleTitle = '".$title."', Category = '".$cat."', ArticleDate = '".date('Y-m-d H:i:s')."', ArticleContent = '".$content."' ".
  63.         "WHERE ArticleTitle = '".$title."'";
  64.        
  65.     $result = mysql_query($query) or die ("Could not update the article:<br />".$mysql_error());
  66.     header("Location: index.php?result=success");
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement