Public feed
#531596
if ((isset($_GET['id'])) && (is_numeric($_GET['id']))){ $id = $_GET['id']; } elseif ((isset($_POST['id'])) && (is_numeric($_POST['id']))){ $id = $_POST['id']; } else { exit("Please choose a news post to edit."); } if (isset($_POST['submitted'])){ $errors = array(); if (empty($_POST['title'])){ $errors[] = 'You forgot to enter a title.'; } else { $title = $_POST['title']; } if (empty($_POST['name'])){ $errors[] = 'You forgot to enter an author.'; } else { $name = $_POST['name']; } if (empty($_POST['message'])){ $errors[] = 'You forgot to enter a message'; } else { $post = $_POST['post']; } if (empty($errors)){ $query = "UPDATE news_posts SET title='$title', author='$author', post='$post' WHERE id=$id"; $result = mysql_query($query); if ($result){ echo "News Post Has Been Updated!"; } else { echo "News post could not be updated."; } } else { echo "News post could not be updated for the following reasons...<br />"; foreach ($errors as $msg) { echo " - $msg<br />\n"; } } } else { $query = "SELECT * FROM news_posts WHERE id = '$id'"; $result = mysql_query($query); $num = mysql_num_rows($result); $row = mysql_fetch_array($result, MYSQL_NUM); $title = $row['title']; $author = $row['author']; $post = $row['post']; if ($num == 1){ ?> <h1 style="margin-bottom: 10px;">Edit news</h1> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <label for="title">Title<span style="color: rgb(208, 0, 0);">*</span></label> <input name="title" value="<?php echo ''.$title.'' ?>" type="text" maxlength="60"> <br /> <label for="name"></label> <input name="name" value="<?php if(isset($_POST['author'])) echo clean($_POST['author']); echo $user['username']; ?>" type="hidden"> <br /> <label for="message">Message<span style="color: rgb(208, 0, 0);">*</span></label> <textarea name="message" rows="7" cols="55"><?php echo ''.$post.'' ?></textarea> <br /> <label for="submit"></label> <input type="submit" name="submit" value="Publish News"> <input type="hidden" name="id" value="<?php echo ''.$id.'' ?>"> <br /><br /> <span style="color: #D00000;">*</span> indicates a required field. </form> <?php } else { echo "News post could not be edited, please try again."; } }