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.
This commit is contained in:
parent
683bca276e
commit
0ee662067d
|
@ -16,7 +16,7 @@
|
||||||
<a href="../index.html">Back Home</a>
|
<a href="../index.html">Back Home</a>
|
||||||
</nav>
|
</nav>
|
||||||
<main>
|
<main>
|
||||||
<form action="./restore.php" method="post">
|
<form action="./submit-sql.php" method="post">
|
||||||
<input type="text" name="fname" placeholder="name"></input>
|
<input type="text" name="fname" placeholder="name"></input>
|
||||||
<input type="text" name="fmessage" placeholder="Message"></input>
|
<input type="text" name="fmessage" placeholder="Message"></input>
|
||||||
<input type="submit"></input>
|
<input type="submit"></input>
|
||||||
|
|
|
@ -16,22 +16,26 @@ class data {
|
||||||
$this->nlength = strlen($this->name);
|
$this->nlength = strlen($this->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($_SERVER["HTTP_HOST"])) {
|
if (!isset($_SERVER["HTTP_HOST"])) {
|
||||||
parse_str($argv[1], $_POST);
|
parse_str($argv[1], $_POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Make ndata Object
|
||||||
$ndata = new data();
|
$ndata = new data();
|
||||||
|
|
||||||
|
# Setup Variables for name and Message
|
||||||
$name = $ndata->name = htmlspecialchars($_POST["fname"]);
|
$name = $ndata->name = htmlspecialchars($_POST["fname"]);
|
||||||
$message = $ndata->message = htmlspecialchars($_POST["fmessage"]);
|
$message = $ndata->message = htmlspecialchars($_POST["fmessage"]);
|
||||||
|
|
||||||
|
# Setup Misc Info like date and lengths
|
||||||
$ndata->set_date();
|
$ndata->set_date();
|
||||||
$ndata->set_mlength();
|
$ndata->set_mlength();
|
||||||
$ndata->set_nlength();
|
$ndata->set_nlength();
|
||||||
$mlength = $ndata->mlength;
|
$mlength = $ndata->mlength;
|
||||||
$nlength = $ndata->nlength;
|
$nlength = $ndata->nlength;
|
||||||
|
|
||||||
|
# Setup Redirect URL
|
||||||
$newURL = "https://" . $_SERVER['SERVER_NAME'] . "/guestbook/index.html";
|
$newURL = "https://" . $_SERVER['SERVER_NAME'] . "/guestbook/index.html";
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,8 +61,9 @@ if($nlength > 25 ) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The DBH Info
|
||||||
$dbh = new PDO('sqlite:/home/evan/Development/Website-Redesign/static/guestbook/database.sq3');
|
$dbh = new PDO('sqlite:/home/evan/Development/Website-Redesign/static/guestbook/database.sq3');
|
||||||
|
# THe Schema For the table
|
||||||
function setupdb($dbh) {
|
function setupdb($dbh) {
|
||||||
$dbh->exec('CREATE TABLE IF NOT EXISTS messages (
|
$dbh->exec('CREATE TABLE IF NOT EXISTS messages (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
|
@ -69,11 +74,11 @@ function setupdb($dbh) {
|
||||||
nlength INTEGER NOT NULL
|
nlength INTEGER NOT NULL
|
||||||
)');
|
)');
|
||||||
}
|
}
|
||||||
function additem($ndata) {
|
# Adding an Item
|
||||||
|
function additem($ndata, $dbh) {
|
||||||
$sql = 'INSERT INTO messages
|
$sql = 'INSERT INTO messages
|
||||||
(id, name, date, message, mlength, nlength)
|
(id, name, date, message, mlength, nlength)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)';
|
VALUES (?, ?, ?, ?, ?, ?)';
|
||||||
$dbh = new PDO('sqlite:/home/evan/Development/Website-Redesign/static/guestbook/database.sq3');
|
|
||||||
$sth = $dbh->prepare($sql);
|
$sth = $dbh->prepare($sql);
|
||||||
$sth->execute(array(
|
$sth->execute(array(
|
||||||
null->id,
|
null->id,
|
||||||
|
@ -83,11 +88,11 @@ function additem($ndata) {
|
||||||
$ndata->mlength,
|
$ndata->mlength,
|
||||||
$ndata->nlength
|
$ndata->nlength
|
||||||
));
|
));
|
||||||
// Commit the Changes
|
|
||||||
// $dbh->commit();
|
|
||||||
}
|
}
|
||||||
|
# Setup the Database (If table does not already exist)
|
||||||
setupdb($dbh);
|
setupdb($dbh);
|
||||||
additem($ndata);
|
|
||||||
print_r($ndata);
|
# Add the Item
|
||||||
print($ndata->name);
|
additem($ndata, $dbh);
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue