-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinser_new_charter-boat.php
66 lines (54 loc) · 2.18 KB
/
inser_new_charter-boat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once 'sql.php';
echo '<pre>';
print_r($_POST);
echo '</pre>';
// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve the form data
$title = $_POST['title'];
$chartercompany = $_POST['chartercompany'];
$boatName = $_POST['boatName'];
$type = $_POST['type'];
$make = $_POST['make'];
$lengthFt = $_POST['lengthFt'];
$lengthMtrs = $_POST['lengthMtrs'];
$notes = $_POST['notes'];
$homePort = $_POST['homePort'];
$homeCountry = $_POST['homeCountry'];
$mailingList = isset($_POST['mailingList']) ? 1 : 0;
// Prepare the SQL statement
$stmt = $conn->prepare("INSERT INTO `boat info` (Title, `charter company`, `Boat Name`, Type, Make, `Length (ft)`, `Length (mtrs)`, Notes, `Home Port`, `Home Country`, `Mailing List`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if (!$stmt) {
echo "Error during statement preparation: " . $conn->error;
}
// Bind the parameters to the statement
$stmt->bind_param("sssssddsssi", $title, $chartercompany, $boatName, $type, $make, $lengthFt, $lengthMtrs, $notes, $homePort, $homeCountry, $mailingList);
// Execute the statement
if ($stmt->execute()) {
echo
$boatId = $stmt->insert_id; // Get the auto-incremented boat ID
echo "Boat registration successful! Boat ID: " . $boatId;
// Create a new entry in the 'dates' table
$firstName = $_POST['firstName'];
$customerSurname = $_POST['customerSurname'];
$email = $_POST['email'];
$notes = "Name: " . $firstName . " " . $customerSurname . ", Email: " . $email;
$datesStmt = $conn->prepare("INSERT INTO `dates` (Note, ID) VALUES (?, ?)");
$datesStmt->bind_param("si", $notes, $boatId);
if ($datesStmt->execute()) {
echo "Dates entry created successfully!";
} else {
echo "Error creating Dates entry: " . $datesStmt->error;
}
$datesStmt->close();
} else {
echo "Error: " . $stmt->error;
}
// Close the statement
$stmt->close();
}
// Close the database connection
$conn->close();
?>