Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "password";
- $dbname = "myDB";
- $tbname = "myVis";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $sql = "SELECT * FROM " . $tbname . " WHERE id = '$_POST[id]'";
- $result = mysqli_query($conn, $sql);
- if (mysqli_num_rows($result) > 0) {
- while($row = mysqli_fetch_assoc($result)) {
- $id = $row['id'];
- $firstname = $row['firstname'];
- $lastname = $row['lastname'];
- $image = $row['image'];
- $course = $row['course'];
- $frdate = $row['frdate'];
- $todate = $row['todate'];
- $email = $row['email'];
- $checkout = $row['checkout'];
- }
- }
- mysqli_close($conn);
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- ...
- </head>
- <body>
- <form action='' method='post'>
- <table>
- ...
- <tr>
- <td>Efternamn:</td>
- <td>
- <input id="lastname2" type="text" value='<?php echo $lastname; ?>' /></td>
- </tr>
- ...
- </table>
- <?php
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (isset($_POST['submit2'])) {
- ...
- if (isset($_POST['lastname2'])) {
- $lastname = $_POST['lastname2'];
- }
- ...
- $servername = "localhost";
- $username = "root";
- $password = "password";
- $dbname = "myDB";
- $tbname = "myVis";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $sql2 = "UPDATE " . $tbname . " SET firstname='$firstname', lastname='$lastname', image='$image', course='$course', frdate='$frdate', todate='$todate', email='$email', checkout='$checkout' WHERE id ='".$_POST['id']."'";
- $result = mysqli_query($conn, $sql2);
- if ($result) {
- echo "Record updated successfully";
- } else {
- echo "Error updating record: " . mysqli_error($conn);
- }
- mysqli_close($conn);
- }
- }
- ?>
- <input type="submit" name="submit2" id="submit2" value="Spara" />
- <input type="button" name="back" id="back" value="Tillbaka" onclick="history.back()" />
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment