added basic functionality
This commit is contained in:
parent
ab910fa13c
commit
e0224f867b
44
index.php
44
index.php
@ -20,4 +20,48 @@
|
|||||||
|
|
||||||
include_once 'config.php';
|
include_once 'config.php';
|
||||||
|
|
||||||
|
function check_word($word) {
|
||||||
|
if (!isset($_POST[$word])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$final = trim($_POST[$word]);
|
||||||
|
if (strlen($final) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strpos($final, ' ') === false) {
|
||||||
|
return htmlspecialchars($final);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['words'])) {
|
||||||
|
// generic check whether all words were entered
|
||||||
|
$word1 = check_word("word1");
|
||||||
|
$word2 = check_word("word2");
|
||||||
|
$word3 = check_word("word3");
|
||||||
|
if ($word1 === false || $word2 === false || $word3 === false) {
|
||||||
|
$_SESSION['flash'] = "Not all words entered are valid.";
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$author = htmlspecialchars(trim($_POST['author']));
|
||||||
|
if (strlen($author) == 0) {
|
||||||
|
$author = "Anonymous";
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_str = "INSERT INTO `words` (`word1`, `word2`, `word3`, `author`, `new`) VALUES ('" . $sql->real_escape_string($word1) . "', '" . $sql->real_escape_string($word2) . "', '" . $sql->real_escape_string($word3) . "', '" . $sql->real_escape_string($author) . "', 1);";
|
||||||
|
|
||||||
|
if (!$sql->query($sql_str)) {
|
||||||
|
$_SESSION['flash'] = "An error occurred: " . $sql->error;
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$_SESSION['flash'] = "Thank you!";
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
$tpl->draw("index");
|
$tpl->draw("index");
|
@ -5,22 +5,25 @@
|
|||||||
<div class="alert alert-info">{$message}</div>
|
<div class="alert alert-info">{$message}</div>
|
||||||
{/if}
|
{/if}
|
||||||
<h1 class="text-center">{$site_name}!</h1>
|
<h1 class="text-center">{$site_name}!</h1>
|
||||||
<p class="text-center">Want to tell them who you are? <input id="author" type="text" class="input-xs" placeholder="Anonymous"></p>
|
<form method="POST">
|
||||||
<div class="row">
|
<p class="text-center">Want to tell them who you are? <input name="author" type="text" class="input-xs" placeholder="Anonymous"></p>
|
||||||
<div class="col-md-4 rowm">
|
<div class="row">
|
||||||
<input id="word1" type="text" class="form-control" placeholder="First Word">
|
<div class="col-md-4 rowm">
|
||||||
|
<input name="word1" type="text" class="form-control" placeholder="First Word">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 rowm">
|
||||||
|
<input name="word2" type="text" class="form-control" placeholder="Second Word">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 rowm">
|
||||||
|
<input name="word3" type="text" class="form-control" placeholder="Third Word">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 rowm">
|
<div class="row">
|
||||||
<input id="word2" type="text" class="form-control" placeholder="Second Word">
|
<div class="col-md-4 col-md-offset-4">
|
||||||
|
<button type="submit" class="btn btn-primary btn-block btn-lg">Submit</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 rowm">
|
<input type="hidden" name="words">
|
||||||
<input id="word3" type="text" class="form-control" placeholder="Third Word">
|
</form>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4 col-md-offset-4">
|
|
||||||
<button type="submit" class="btn btn-primary btn-block btn-lg">Submit</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{include="footer"}
|
{include="footer"}
|
@ -18,7 +18,7 @@
|
|||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{$user_name}<b class="caret"></b></a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{$user_name}<b class="caret"></b></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="ucp.php">Inbox{if="$new_words_count > 0"} ({$new_words_count}){/if}</a></li>
|
<li><a href="ucp.php">Inbox{if="$inbox_count > 0"} ({$inbox_count}){/if}</a></li>
|
||||||
<li><a href="ucp.php?page=settings">Settings</a></li>
|
<li><a href="ucp.php?page=settings">Settings</a></li>
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li><a href="ucp.php?page=logout">Logout</a></li>
|
<li><a href="ucp.php?page=logout">Logout</a></li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user