Fatal error: Uncaught Error...
Dit zijn de scriptjes om gegevens weg te schrijven naar een database:
2-reserve.php
Code (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class Reservation {
// (A) CONSTRUCTOR - CONNECT TO DATABASE
private $pdo; // pdo object
private $stmt; // sql statement
public $error; // error message
function construct() {
$this->pdo = new PDO(
"mysql:host=**knip**" . DB_HOST . "dbname=**knip**" . DB_NAME . "charset=utf8mb4" . DB_CHARSET . "dbuser=**knip**" . DB_USER . "dbpassword=**knip**" . DB_PASSWORD, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_NAMED
]);
}
class DatabaseConnection {
public function __construct() {
try {
return new PDO('mysqli:host=xxx;dbname=xxx', 'root', '');
} catch(PDOException $e) {
exit('Database error');
}
}
}
// (B) DESTRUCTOR - CLOSE DATABASE CONNECTION
function destruct() {
$this->pdo = null;
$this->stmt = null;
}
// (C) HELPER - EXECUTE SQL QUERY
function query ($sql, $data=null) : void {
$this->stmt = $this->pdo->prepare($sql);
$this->stmt->execute($data);
}
// (D) SAVE RESERVATION
function save ($date, $slot, $name, $email, $tel, $notes="") {
// (D1) CHECKS & RESTRICTIONS
// @TODO - ADD YOUR OWN RULES & REGULATIONS HERE
// MAX # OF RESERVATIONS ALLOWED?
// USER CAN ONLY BOOK X DAYS IN ADVANCE?
// USER CAN ONLY BOOK A MAX OF X SLOTS WITHIN Y DAYS?
// (D2) DATABASE ENTRY
$this->query(
"INSERT INTO reservations (`res_date`, `res_slot`, `res_name`, `res_email`, `res_tel`, `res_notes`) VALUES (?,?,?,?,?,?)",
[$date, $slot, $name, $email, $tel, $notes]
);
// (D3) EMAIL
// @TODO - REMOVE IF YOU WANT TO MANUALLY CALL TO CONFIRM OR SOMETHING
// OR EMAIL THIS TO A MANAGER OR SOMETHING
$subject = "Reservation Received";
$message = "Thank you, we have received your request and will process it shortly.";
@mail($email, $subject, $message);
return true;
}
// (E) GET RESERVATIONS FOR THE DAY
function getDay ($day="") {
// (E1) DEFAULT TO TODAY
if ($day=="") { $day = date("Y-m-d"); }
// (E2) GET ENTRIES
$this->query("SELECT * FROM reservations WHERE res_date=?", [$day]);
return $this->stmt->fetchAll();
}
}
// (F) DATABASE SETTINGS - CHANGE THESE TO YOUR OWN!
define("DB_HOST", "***************");
define("DB_NAME", "*************");
define("DB_CHARSET", "utf8mb4");
define("DB_USER", "********");
define("DB_PASSWORD", "*********");
// (G) NEW RESERVATION OBJECT
$_RSV = new Reservation();
?>
class Reservation {
// (A) CONSTRUCTOR - CONNECT TO DATABASE
private $pdo; // pdo object
private $stmt; // sql statement
public $error; // error message
function construct() {
$this->pdo = new PDO(
"mysql:host=**knip**" . DB_HOST . "dbname=**knip**" . DB_NAME . "charset=utf8mb4" . DB_CHARSET . "dbuser=**knip**" . DB_USER . "dbpassword=**knip**" . DB_PASSWORD, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_NAMED
]);
}
class DatabaseConnection {
public function __construct() {
try {
return new PDO('mysqli:host=xxx;dbname=xxx', 'root', '');
} catch(PDOException $e) {
exit('Database error');
}
}
}
// (B) DESTRUCTOR - CLOSE DATABASE CONNECTION
function destruct() {
$this->pdo = null;
$this->stmt = null;
}
// (C) HELPER - EXECUTE SQL QUERY
function query ($sql, $data=null) : void {
$this->stmt = $this->pdo->prepare($sql);
$this->stmt->execute($data);
}
// (D) SAVE RESERVATION
function save ($date, $slot, $name, $email, $tel, $notes="") {
// (D1) CHECKS & RESTRICTIONS
// @TODO - ADD YOUR OWN RULES & REGULATIONS HERE
// MAX # OF RESERVATIONS ALLOWED?
// USER CAN ONLY BOOK X DAYS IN ADVANCE?
// USER CAN ONLY BOOK A MAX OF X SLOTS WITHIN Y DAYS?
// (D2) DATABASE ENTRY
$this->query(
"INSERT INTO reservations (`res_date`, `res_slot`, `res_name`, `res_email`, `res_tel`, `res_notes`) VALUES (?,?,?,?,?,?)",
[$date, $slot, $name, $email, $tel, $notes]
);
// (D3) EMAIL
// @TODO - REMOVE IF YOU WANT TO MANUALLY CALL TO CONFIRM OR SOMETHING
// OR EMAIL THIS TO A MANAGER OR SOMETHING
$subject = "Reservation Received";
$message = "Thank you, we have received your request and will process it shortly.";
@mail($email, $subject, $message);
return true;
}
// (E) GET RESERVATIONS FOR THE DAY
function getDay ($day="") {
// (E1) DEFAULT TO TODAY
if ($day=="") { $day = date("Y-m-d"); }
// (E2) GET ENTRIES
$this->query("SELECT * FROM reservations WHERE res_date=?", [$day]);
return $this->stmt->fetchAll();
}
}
// (F) DATABASE SETTINGS - CHANGE THESE TO YOUR OWN!
define("DB_HOST", "***************");
define("DB_NAME", "*************");
define("DB_CHARSET", "utf8mb4");
define("DB_USER", "********");
define("DB_PASSWORD", "*********");
// (G) NEW RESERVATION OBJECT
$_RSV = new Reservation();
?>
tweede script: 3-reservation-php
Code (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
67
68
69
70
71
72
73
74
75
76
77
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
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<title>DUMMY RESERVATION PAGE</title>
<meta charset="utf-8">
<link href="3-theme.css" rel="stylesheet">
</head>
<body>
<?php
// (A) PROCESS RESERVATION
if (isset($_POST["date"])) {
require "2-reserve.php";
if ($_RSV->save(
$_POST["date"], $_POST["slot"], $_POST["name"],
$_POST["email"], $_POST["tel"], $_POST["notes"])) {
echo "<div class='note'>Reservation saved.</div>";
} else { echo "<div class='note'>".$_RSV->error."</div>"; }
}
?>
<!-- (B) RESERVATION FORM -->
<form id="resForm" method="post" target="_self">
<label>Name</label>
<input type="text" required name="name" value="Jon Doe">
<label>Email</label>
<input type="email" required name="email" value="[email protected]">
<label>Telephone Number</label>
<input type="text" required name="tel" value="123456789">
<label>Notes (if any)</label>
<input type="text" name="notes" value="Testing">
<?php
// @TODO - MINIMUM DATE (TODAY)
// $mindate = date("Y-m-d", strtotime("+2 days"));
$mindate = date("Y-m-d");
?>
<label>Reservation Date</label>
<input type="date" required name="date" min="<?=$mindate?>">
<label>Reservation Slot</label>
<select name="slot">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
Derde script: 4-report.php
<?php
// (A) GET ALL RESERVATIONS
require "2-reserve.php";
$all = $_RSV->getDay();
// (B) OUTPUT CSV
header("Content-Type: text/csv");
header("Content-Disposition: attachment;filename=reservations.csv");
if (count($all)==0) { echo "No reservations"; }
else {
// (B1) FIRST ROW - HEADERS
foreach ($all[0] as $k=>$v) { echo "$k,"; }
echo "\r\n";
// (B2) RESERVATION DETAILS
foreach ($all as $r) {
foreach ($r as $k=>$v) { echo "$v,"; }
echo "\r\n";
}
}
?>
<html>
<head>
<title>DUMMY RESERVATION PAGE</title>
<meta charset="utf-8">
<link href="3-theme.css" rel="stylesheet">
</head>
<body>
<?php
// (A) PROCESS RESERVATION
if (isset($_POST["date"])) {
require "2-reserve.php";
if ($_RSV->save(
$_POST["date"], $_POST["slot"], $_POST["name"],
$_POST["email"], $_POST["tel"], $_POST["notes"])) {
echo "<div class='note'>Reservation saved.</div>";
} else { echo "<div class='note'>".$_RSV->error."</div>"; }
}
?>
<!-- (B) RESERVATION FORM -->
<form id="resForm" method="post" target="_self">
<label>Name</label>
<input type="text" required name="name" value="Jon Doe">
<label>Email</label>
<input type="email" required name="email" value="[email protected]">
<label>Telephone Number</label>
<input type="text" required name="tel" value="123456789">
<label>Notes (if any)</label>
<input type="text" name="notes" value="Testing">
<?php
// @TODO - MINIMUM DATE (TODAY)
// $mindate = date("Y-m-d", strtotime("+2 days"));
$mindate = date("Y-m-d");
?>
<label>Reservation Date</label>
<input type="date" required name="date" min="<?=$mindate?>">
<label>Reservation Slot</label>
<select name="slot">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
Derde script: 4-report.php
<?php
// (A) GET ALL RESERVATIONS
require "2-reserve.php";
$all = $_RSV->getDay();
// (B) OUTPUT CSV
header("Content-Type: text/csv");
header("Content-Disposition: attachment;filename=reservations.csv");
if (count($all)==0) { echo "No reservations"; }
else {
// (B1) FIRST ROW - HEADERS
foreach ($all[0] as $k=>$v) { echo "$k,"; }
echo "\r\n";
// (B2) RESERVATION DETAILS
foreach ($all as $r) {
foreach ($r as $k=>$v) { echo "$v,"; }
echo "\r\n";
}
}
?>
Gewijzigd op 24/07/2023 14:48:34 door - Ariën -
Ook is het niet handig om je mail-fucntie te onderdrukken. En ik raad aan om hier ook een if-else statement in te bouwen. het wil wel eens gebeuren dat mail() soms een false geeft, en ook dát wil je graag opvangen.
Zie ook je PM van huishoudelijke aard die ik je zo stuur.
Gewijzigd op 24/07/2023 12:42:21 door - Ariën -
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2019] Unknown character set in /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php:8 Stack trace: #0 /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php(8): PDO->__construct('mysql:host=nouv...', 'nouvelle_cuisin...', Object(SensitiveParameterValue), Array) #1 /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php(70): Reservation->__construct() #2 /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/3-reservation.php(12): require('/customers/7/5/...') #3 {main} thrown in /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php on line 8
het script werd gedownload van https://code-boxx.com/simple-php-reservation-system/
Idem dito voor de rest in de connect.
Je hebt het zelf verkeerd ingevuld.
Gewijzigd op 24/07/2023 14:45:12 door - Ariën -
function __construct() {
$this->pdo = new PDO(
"mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET,
DB_USER, DB_PASSWORD, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_NAMED
]);
}
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'nouvelle_cuisine_bereservaties'@'10.27.53.18' (using password: YES) in /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php:8 Stack trace: #0 /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php(8): PDO->__construct('mysql:host=loca...', 'nouvelle_cuisin...', Object(SensitiveParameterValue), Array) #1 /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php(70): Reservation->__construct() #2 /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/3-reservation.php(12): require('/customers/7/5/...') #3 {main} thrown in /customers/7/5/6/nouvelle-cuisine.be/httpd.www/reservaties/2-reserve.php on line 8
Ik wil niet opdringerig zijn, maar ik raad je aan om je privé bericht goed te lezen.
Nu over het probleem,...is dat script aan het praten te krijgen of beter meteen de prullenmand in?
Dit probleem heeft niks met je script te maken, maar met je inloggegevens die niet lijken te kloppen.
Is het nog gelukt, Marcus? Graag een terugkoppeling.