2024-06-09 14:49:18 -05:00
|
|
|
<?php
|
|
|
|
# Setup Data Object
|
|
|
|
class data {
|
|
|
|
public $name;
|
|
|
|
public $message;
|
|
|
|
public $date;
|
|
|
|
public $mlength;
|
|
|
|
public $nlength;
|
|
|
|
function set_date() {
|
|
|
|
$this->date = date("Y M d");
|
|
|
|
}
|
|
|
|
function set_mlength() {
|
|
|
|
$this->mlength = strlen($this->message);
|
|
|
|
}
|
|
|
|
function set_nlength() {
|
|
|
|
$this->nlength = strlen($this->name);
|
|
|
|
}
|
|
|
|
}
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
|
2024-06-09 14:49:18 -05:00
|
|
|
if (!isset($_SERVER["HTTP_HOST"])) {
|
|
|
|
parse_str($argv[1], $_POST);
|
|
|
|
}
|
|
|
|
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
# Make ndata Object
|
2024-06-09 14:49:18 -05:00
|
|
|
$ndata = new data();
|
|
|
|
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
# Setup Variables for name and Message
|
2024-06-09 14:49:18 -05:00
|
|
|
$name = $ndata->name = htmlspecialchars($_POST["fname"]);
|
|
|
|
$message = $ndata->message = htmlspecialchars($_POST["fmessage"]);
|
|
|
|
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
# Setup Misc Info like date and lengths
|
2024-06-09 14:49:18 -05:00
|
|
|
$ndata->set_date();
|
|
|
|
$ndata->set_mlength();
|
|
|
|
$ndata->set_nlength();
|
|
|
|
$mlength = $ndata->mlength;
|
|
|
|
$nlength = $ndata->nlength;
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
|
|
|
|
# Setup Redirect URL
|
2024-06-09 14:49:18 -05:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
# The DBH Info
|
2024-06-09 14:49:18 -05:00
|
|
|
$dbh = new PDO('sqlite:/home/evan/Development/Website-Redesign/static/guestbook/database.sq3');
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
# THe Schema For the table
|
2024-06-09 14:49:18 -05:00
|
|
|
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
|
|
|
|
)');
|
|
|
|
}
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
# Adding an Item
|
|
|
|
function additem($ndata, $dbh) {
|
2024-06-09 14:49:18 -05:00
|
|
|
$sql = 'INSERT INTO messages
|
|
|
|
(id, name, date, message, mlength, nlength)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?)';
|
|
|
|
$sth = $dbh->prepare($sql);
|
|
|
|
$sth->execute(array(
|
|
|
|
null->id,
|
|
|
|
$ndata->name,
|
|
|
|
$ndata->date,
|
|
|
|
$ndata->message,
|
|
|
|
$ndata->mlength,
|
|
|
|
$ndata->nlength
|
|
|
|
));
|
|
|
|
}
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
# Setup the Database (If table does not already exist)
|
2024-06-09 14:49:18 -05:00
|
|
|
setupdb($dbh);
|
Add comments & Update URL Sceheme
This adds many comments to submit-sql.php file (previously restore.php), and renames the file, this is the start of this, and thus pulling from the SQL database is not yet supported. I also do not have checking for duplicates, but I feel like that could be done in-database. This is currently using a development SQLite database, and will eventually use postgresql. I need to find out a way to obscure credentials to PostgreSQL, maybe loading it from a ignored file, which would be git ignored? The SQL Implmentation is not production-ready, and also I need to figure out a better solution when switching from JSON TO SQL, as I plan to support both in this project. There needs to be alot of refactoring done in the submisson code, as this is just a *really* early draft.
2024-06-09 15:39:05 -05:00
|
|
|
|
|
|
|
# Add the Item
|
|
|
|
additem($ndata, $dbh);
|
|
|
|
|
2024-06-09 14:49:18 -05:00
|
|
|
?>
|