Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // articles.php
- // Design the form based on the action the user selected.
- <?php
- $action = $_GET["action"];
- $target = $_GET["target"];
- if ($action == "Edit") {
- $query = "SELECT * FROM Articles WHERE ArticleTitle = '".$target."'";
- $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
- if (mysql_num_rows($result) > 0) {
- list($ArticleID, $Category, $ArticleDate, $ArticleTitle, $ArticleContent) = mysql_fetch_row($result);
- $cat = $Category;
- $title = $ArticleTitle;
- $content = $ArticleContent;
- }
- $query = "SELECT CategoryName FROM Categories WHERE DeletedYN = 'No'";
- $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
- echo "<form name=\"editarticle\" method=\"post\" action=\"articlework.php\">".
- "<table>".
- "<tr>".
- "<td>Article Title<br /><input type=\"text\" name=\"article_title\" value=\"".$title."\" style=\"width: 300px;\" /></td>".
- "<td>Category<br />".
- "<select name=\"article_cat\">".
- "<option selected value=\"".$cat."\">".$cat."</option>";
- if (mysql_num_rows($result) > 0) {
- while($row = mysql_fetch_array($result)) {
- echo "<option value=\"".$row['CategoryName']."\">".$row['CategoryName']."</option>";
- }
- }
- echo "</tr>".
- "<tr>".
- "<td colspan=\"2\"><textarea id=\"article_content\" name=\"article_content\" rows=\"15\" cols=\"80\" style=\"width: 80%;\">".$content."</textarea>".
- "<tr>".
- "</table>".
- "<div class=\"RightAlign\"><input type=\"submit\" name=\"btnSubmit\" value=\"Update Article\" /></div>".
- "</form>";
- }
- ?>
- //articlework.php
- // Update the article to save the changes made by the user.
- <?php
- $title = $_GET["article_title"];
- $cat = $_GET["article_cat"];
- $content = $_GET["article_content"];
- // Set database server access variables:
- $host = "localhost";
- $user = "root";
- $pass = "root";
- $db = "logansarchive";
- // Open connection
- $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
- // Select database
- mysql_select_db($db) or die ("Unable to select database!");
- $query = "UPDATE Articles ".
- "SET ArticleTitle = '".$title."', Category = '".$cat."', ArticleDate = '".date('Y-m-d H:i:s')."', ArticleContent = '".$content."' ".
- "WHERE ArticleTitle = '".$title."'";
- $result = mysql_query($query) or die ("Could not update the article:<br />".$mysql_error());
- header("Location: index.php?result=success");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement