The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Product updateBCA
By Guest on 26th July 2024 12:24:44 AM | Syntax: PYTHON | Views: 31



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. <?php
  2. $servername = 'localhost';
  3. $username = 'root';
  4. $password = 'user@123';
  5. $dbname = 'publish';
  6. $conn = new mysqli($servername, $username, $password, $dbname);
  7. if ($conn->connect_error) {
  8.  die("Connection failed: " . $conn->connect_error);
  9. }
  10. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  11.  $title = $_POST["title"];
  12.  $author = $_POST["author"];
  13.  $edition = $_POST["edition"];
  14.  $no_of_copies = $_POST["no_of_copies"];
  15.  $sql = "SELECT * FROM books WHERE title = '$title' AND author = '$author' AND edition =
  16. '$edition'";
  17.  $result = $conn->query($sql);
  18.  if ($result->num_rows > 0) {
  19.  $row = $result->fetch_assoc();
  20.  $new_copies = $row["no_of_copies"] + $no_of_copies;
  21.  $update_sql = "UPDATE books SET no_of_copies = '$new_copies' WHERE id = " .
  22. $row["id"];
  23.  if ($conn->query($update_sql) === TRUE) {
  24.  echo "Book details updated successfully.";
  25.  } else {
  26.  echo "Error updating book details: " . $conn->error;
  27.  }
  28.  } else {
  29.  $insert_sql = "INSERT INTO books (title, author, edition, no_of_copies) VALUES ('$title',
  30. '$author', '$edition', '$no_of_copies')";
  31.  if ($conn->query($insert_sql) === TRUE) {
  32.  echo "New book inserted successfully.";
  33.  } else {
  34.  echo "Error inserting new book: " . $conn->error;
  35.  }
  36.  }
  37. }
  38. ?>
  39. <html>
  40. <head>
  41.  <title>Insert Book Details</title>
  42. </head>
  43. <body>
  44.  <h2>Insert Book Details</h2>
  45.  <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
  46.  Title: <input type="text" name="title" required><br><br>
  47.  Author: <input type="text" name="author" required><br><br>
  48.  Edition: <input type="text" name="edition" required><br><br>
  49.  Number of Copies: <input type="number" name="no_of_copies" required><br><br>
  50.  <input type="submit" value="Submit">
  51.  </form>
  52. </body>
  53. </html>
  54. <?php
  55.  
  56. $conn->close();
  57. ?>





product updatebca