Advertisement
Squito

Untitled

Sep 3rd, 2023 (edited)
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2. /* Connect and database verify */
  3. if(isset($_GET['id']))
  4. {
  5.     include('../inc/connect.php');
  6.     $id = $_GET['id'];
  7.     // Fetch the record by ID
  8.     $prep=mysqli_stmt_init($conn);
  9.     mysqli_stmt_prepare($prep, "SELECT id, nev, email FROM tanulok WHERE id = ?");
  10.     mysqli_stmt_bind_param($prep, "i", $id);
  11.     mysqli_stmt_execute($prep);
  12.     mysqli_stmt_store_result($prep);
  13.     if(mysqli_stmt_num_rows($prep)==0)
  14.     {
  15.         $id=$nev=$email='';
  16.         //+Hibaüzenet
  17.     }
  18.     else
  19.     {
  20.         mysqli_stmt_bind_result($prep, $id, $nev, $email);
  21.         mysqli_stmt_fetch($prep);
  22.     }
  23.     mysqli_stmt_close($prep);
  24. }
  25. else
  26. {
  27.     die("Record ID not specified.");
  28. }
  29.  
  30. if(isset($_POST['id']))
  31. {
  32.     include('../inc/connect.php');
  33.     // Process the form submission and update the record
  34.     $newName = $_POST['newName'];
  35.     $newEmail = $_POST['newEmail'];
  36.     $id = $_POST['id'];
  37.     $prep=mysqli_stmt_init($conn);
  38.     mysqli_stmt_prepare($prep, "UPDATE tanulok SET nev=?, email=? WHERE id=?");
  39.     mysqli_stmt_bind_param($prep, "ssi", $newName, $newEmail, $id);
  40.     mysqli_stmt_execute($prep);
  41.     if(mysqli_stmt_affected_rows($prep)==0)
  42.     {
  43.         //Hibaüzenet
  44.     }
  45.     else
  46.     {
  47.         //Sikerült
  48.     }
  49.     mysqli_stmt_close($prep);
  50.  
  51.     header("Location: index.html"); // Redirect back to the records page
  52. }
  53. ?>
  54. <html>
  55. <head>
  56.     <link rel="stylesheet" href="../css/main.css">
  57.     <link rel="stylesheet" href="../css/w3.css">
  58.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/.../css/font-awesome.min.css">
  59.     <title>Tanulói kezelőfelület</title>
  60. </head>
  61. <body>
  62. <div class="main-container-add w3-padding-large">
  63.     <div class="w3-container w3-flat-peter-river margin-b80">
  64.         <h2><i class="fa fa-address-card-o" aria-hidden="true"></i>Tanulói kezelőfelület</h2>
  65.     </div>
  66.     <h2 class="w3-text-deep-purple">Adatok módosítása!</h2>
  67.     <form method="post" action="">
  68.         <input type="hidden" id="id" name="id" class="w3-input" value="<?php echo $id; ?>">
  69.         <label for="newName">Új név</label>
  70.         <input type="text" id="newName" name="newName" class="w3-input" value="<?php echo htmlspecialchars($nev); ?>" required><br>
  71.         <label for="newEmail">Új email:</label>
  72.         <input type="text" id="newEmail" name="newEmail" class="w3-input" value="<?php echo htmlspecialchars($email); ?>" required><br>
  73.         <input type="submit" class="w3-button w3-button w3-deep-purple" value="Módosítás!">
  74.     </form>
  75.     <a href="../php/add.php" class="w3-button w3-button w3-teal">Adatok felvitele</a>
  76.     <a href="view.php" class="w3-button w3-flat-peter-river">Adatok megtekintése</a>
  77. </div>
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement