Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $error_msg = "";
- $succes_msg = "";
- include ("include/connection.inc.php");
- if(isset($_POST['update']))
- {
- $id = $_GET['id'];
- $title = $_POST['title'];
- $category = $_POST['category'];
- $image = $_POST['image'];
- $date = $_POST['date'];
- $content = $_POST['content'];
- switch ($category) {
- case '1':
- $category ='News';
- break;
- case '2':
- $category ='Blog';
- break;
- case '3':
- $category ='Other';
- break;
- }
- if(empty($title) || empty($category) || empty($image) || empty($date) || empty($content) )
- {
- $error_msg = "All fields are required.";
- }
- else
- {
- $sql = "UPDATE posts SET title='$title', category='$category', date_created='$date', image ='$image', content='$'content' WHERE id=$id";
- $result = mysqli_query($conn, $sql);
- if($sql == TRUE)
- {
- $succes_msg ="Post successfully updated.";
- }
- else
- {
- $error_msg = "Failed.";
- }
- //UPDATE table_name SET column1=value, column2=value2,... WHERE column_name=some_value
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>PHP&MySQL - Edit post</title>
- <link rel="stylesheet" type="text/css" href="css/style.css">
- </head>
- <body>
- <nav>
- <div class="logout">
- <a href="logout.php">Logout</a>
- </div>
- </nav>
- <div class="container">
- <h2>Edit post</h2>
- <hr>
- <form action="" method="POST">
- <p class="add-success"><?php echo $succes_msg; ?></p>
- <p class="post-error"><?php echo $error_msg; ?></p>
- <div class="form-group">
- <label class="label-post">Title</label><input type="text" name="title" value=""/>
- </div>
- <div class="form-group">
- <label class="label-post">Category</label><select name="category">
- <option value="1">News</option>
- <option value="2">Blog</option>
- <option value="3">Other</option>
- </select>
- </div>
- <div class="form-group">
- <label class="label-post">Path to image</label><input type="text" name="image" value=""/>
- </div>
- <div class="form-group">
- <label class="label-post">Date</label><input type="date" name="date" value=""/>
- </div>
- <div class="form-group">
- <label class="label-post" style="vertical-align: top;">Content</label><textarea type="text" name="content" rows="10" cols="80"></textarea>
- </div>
- <div class="form-group>">
- <input type="submit" name="update" class="login-button add-post" value="Update post">
- </div>
- <p>Back to <a href="dashboard.php">Dashboard</a></p>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement