Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";$username = "";$password = "";$dbname = "";
- $id=$_GET['id'];
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare("SELECT title, caption, url, main_image, ordering, state FROM slide WHERE id='$id'");
- $stmt->execute();
- // set the resulting array to associative
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- foreach($stmt->fetchAll() as $key=>$val)
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $title = $_POST["title"];
- $caption = $_POST["caption"];
- $sql = "UPDATE slide SET title='$title', caption='$caption' WHERE id='$id'";
- // Prepare statement
- $stmt = $conn->prepare($sql);
- // execute the query
- $stmt->execute();
- // echo a message to say the UPDATE succeeded
- header("Location: edit.php?id=$id");
- }
- }
- catch(PDOException $e)
- {
- echo $sql . "<br>" . $e->getMessage();
- }
- $conn = null;
- ?>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <p><label>Title</label><input type="text" name="title" value="<?php echo $val['title']; ?>"></p>
- <p><label>caption</label><input type="text" name="caption" value="<?php echo $val['caption']; ?>"></p>
- <p><input type="submit" name="submit" value="Submit" onclick="mySuccessFunction()"></p>
- </form>
Add Comment
Please, Sign In to add comment