From 683bca276e133ab27d986c8e58f0b47f436c2ae2 Mon Sep 17 00:00:00 2001 From: "Evan G." Date: Sun, 9 Jun 2024 14:49:18 -0500 Subject: [PATCH] Rough Draft of SQL Implmentation in PHP --- index.html | 2 +- restore.php | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 restore.php diff --git a/index.html b/index.html index 2e532db..da843bc 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ Back Home
-
+ diff --git a/restore.php b/restore.php new file mode 100644 index 0000000..dd55a42 --- /dev/null +++ b/restore.php @@ -0,0 +1,93 @@ +date = date("Y M d"); + } + function set_mlength() { + $this->mlength = strlen($this->message); + } + function set_nlength() { + $this->nlength = strlen($this->name); + } +} +if (!isset($_SERVER["HTTP_HOST"])) { + parse_str($argv[1], $_POST); +} + + +$ndata = new data(); + + +$name = $ndata->name = htmlspecialchars($_POST["fname"]); +$message = $ndata->message = htmlspecialchars($_POST["fmessage"]); + +$ndata->set_date(); +$ndata->set_mlength(); +$ndata->set_nlength(); +$mlength = $ndata->mlength; +$nlength = $ndata->nlength; +$newURL = "https://" . $_SERVER['SERVER_NAME'] . "/guestbook/index.html"; + + +# Check name and message +if ($name == "") { + header('Refresh:2; url=' . $newURL ); + echo "There is no name, Try again with a name"; + exit(); +} +if ($message == "") { + header('Refresh:2; url=' . $newURL ); + echo "There is no message, Try again with a message"; + exit(); +} +if($mlength > 200) { + header('Refresh:2; url=' . $newURL ); + echo "This message is too long"; + exit(); +} +if($nlength > 25 ) { + header('Refresh:2; url=' . $newURL ); + echo "The name is too long"; + exit(); +} + + +$dbh = new PDO('sqlite:/home/evan/Development/Website-Redesign/static/guestbook/database.sq3'); +function setupdb($dbh) { + $dbh->exec('CREATE TABLE IF NOT EXISTS messages ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + date TEXT NOT NULL, + message TEXT NOT NULL, + mlength INTEGER NOT NULL, + nlength INTEGER NOT NULL + )'); +} +function additem($ndata) { + $sql = 'INSERT INTO messages + (id, name, date, message, mlength, nlength) + VALUES (?, ?, ?, ?, ?, ?)'; + $dbh = new PDO('sqlite:/home/evan/Development/Website-Redesign/static/guestbook/database.sq3'); + $sth = $dbh->prepare($sql); + $sth->execute(array( + null->id, + $ndata->name, + $ndata->date, + $ndata->message, + $ndata->mlength, + $ndata->nlength + )); + // Commit the Changes +// $dbh->commit(); +} +setupdb($dbh); +additem($ndata); +print_r($ndata); +print($ndata->name); +?>