-1

I'm very new to coding, I started last week and I'm trying to create an appointment booking website for an ensurance company in my city. I have a single PHP file using both HTML and PHP languages because I found it more comfortable to work with the form, since I can display both the error message and the succes message under the "Submit" button. I was wondering if there is any way I can put the echo message inside a tag so i could edit it in css maybe creating a box around it or adding an icon to make it stand out more.

<button class="btn">Submit</button>

<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {

htmlspecialchars($_SERVER["PHP_SELF"]);
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$date = $_POST["date"];
$time = $_POST["time"];

if (!empty($name) && !empty($email) && !empty($phone) && !empty($date) && !empty($time)) {

  $host = "localhost";
  $dbname = "appointments";
  $username = "root";
  $password = "";

  $conn = mysqli_connect($host, $username, $password, $dbname);
  if (mysqli_connect_errno()){
    die("Connection error: " . mysqli_connect_errno());
  }

  $sql = "INSERT INTO appuntamenti (name, email, phone, date, time)
          VALUES(?, ?, ?, ?, ?)";

  $stmt = mysqli_stmt_init($conn);

  if ( ! mysqli_stmt_prepare($stmt, $sql)) {
    die(mysqli_error($conn));
  }

  mysqli_stmt_bind_param($stmt, "sssss",
                         $name,
                         $email,
                         $phone,
                         $date,
                         $time);
  mysqli_stmt_execute($stmt);
  echo "<Booking was successful";
}else {
  echo "All fields need to be completed.";
}
}
?>

I was also wondering if there is anyway to remove weekends and holidays from the standard html5 datepicker using only PHP, I already got rid of past dates using this command

<input type="date" name="date" min="<?= date('Y-m-d') ?>">

Let me know if there's anything I'm doing wrong or I could better. Thanks in advance.

  • Here's an overview I wrote of how PHP works, and how it relates to HTML/Javascript: https://stackoverflow.com/questions/72022099/how-to-make-the-value-stored-in-the-php-session-update-with-the-ajax-submission/72023066#72023066 *Spoiler alert:* they don't execute at the same time, or in the same context. – bloodyKnuckles Jun 06 '22 at 17:50
  • https://stackoverflow.com/questions/49863189/disable-weekends-on-html-5-input-type-date – Hamza Zafeer Jun 07 '22 at 11:17

1 Answers1

0

If you want to print PHP code inside a HTML tag. You can print them as well echo "<p>Any text here</p>. Or you can print other tag also like div, h1, span and more.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 07 '22 at 11:13