Hi there,
I just checked your site and the errors I mention previously persist
Anyway, we were 85% of the way there and I thought it was a shame to leave it at that, so I finished this off for you:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>SMS Display Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<style type="text/css">
div {text-align: center}
.results { margin-top: 15px; }
</style>
</head>
<body>
<div data-role="page" id="admin" data-theme="b">
<h2>SMS Display Admin</h2>
<div>
<a href="#newsms"><button data-inline="true">New SMS Message</button></a>
<a href="#removesms"><button data-inline="true">Remove a SMS</button></a>
</div>
<div>
<a href="#newadvert"><button data-inline="true">New Advert Message</button></a>
<a href="#removeadvert"><button data-inline="true">Remove a Advert</button></a>
</div>
<div>
<a href="#newbadword"><button data-inline="true">New Bad Word</button></a>
<a href="#removebadword"><button data-inline="true">Remove a badword</button></a>
</div>
</div>
<!--New SMS Page -->
<div data-role="page" id="newsms" data-theme="b">
<div id="SMSinput">
<form action="submit.php" method="post" id="newSMSForm" class="ajaxForm" data-action="new">
<label for="newsms"><h2>SMS Input:</h2></label>
<input name="content" type="text" size="160" data-mini="true" id="newsms"/>
<input type="hidden" name="sender" value="4477777777777">
<input type="hidden" name="inNumber" value="447786202125">
<input type="hidden" name="email" value="none">
<input type="hidden" name="credits" value="2501">
<input type="hidden" name="forward" value="0">
<input type="hidden" name="messagesent" value="0">
<input name="newsms" data-role="button" data-inline="true" type="submit" value="submit" />
</form>
<a href="#admin" class="back"><button data-inline="true">Back</button></a>
</div>
<div class="results"></div>
</div>
<!--End SMS Page -->
<!--New Advert Page -->
<div data-role="page" id="newadvert" data-theme="b">
<form action="submit.php" method="post" id="newAdvertForm" class="ajaxForm" data-action="new">
<label for="newadvert"><h2>New Advert:</h2></label>
<input name="newadvert" type="text" size="160" id="newadvert" />
<input name="newad" data-role="button" data-inline="true" type="submit" value="submit" />
</form>
<a href="#admin" class="back"><button data-inline="true">Back</button></a>
<div class="results"></div>
</div>
<!--End Advert Page -->
<!--New Bad Word Page -->
<div data-role="page" id="newbadword" data-theme="b">
<form action="submit.php" method="post" id="newBadWordForm" class="ajaxForm" data-action="new">
<label for="newbadword"><h2>New Bad Word:</h2></label>
<input name="newbadword" type="text" size="160" id="newbadword" />
<input name="badword" data-role="button" data-inline="true" type="submit" value="submit" />
</form>
<a href="#admin" class="back"><button data-inline="true">Back</button></a>
<div class="results"></div>
</div>
<!--End Bad Word Page -->
<!--Remove SMS-->
<div data-role="page" id="removesms" data-theme="b">
<form action="submit.php" method="post" id="removeSMSForm" class="ajaxForm" data-action="remove">
<h2>SMS Removal</h2>
<label for="smsid" class="select"><h2>Message:</h2></label>
<select name="smsid" id="smsid" data-mini="true"></select>
<input id="removeSmsButton" name="removesms" type="submit" value="submit" data-role="button" data-inline="true" data-theme="b" />
</form>
<a href="#admin" class="back"><button data-inline="true">Back</button></a>
<div class="results"></div>
</div>
<!--End Remove SMS-->
<!--Remove advert-->
<div data-role="page" id="removeadvert" data-theme="b">
<form action="submit.php" method="post" id="removeAdvertForm" class="ajaxForm" data-action="remove">
<h2>Advert Removal</h2>
<label for="advertid" class="select"><h2>Advert:</h2></label>
<select name="advertid" id="advertid" data-mini="true"></select>
<input id="removeAdvertButton" name="removeadvert" type="submit" value="submit" data-role="button" data-inline="true" data-theme="b" />
</form>
<a href="#admin" class="back"><button data-inline="true">Back</button></a>
<div class="results"></div>
</div>
<!--End Remove advert-->
<!--Remove Bad Word-->
<div data-role="page" id="removebadword" data-theme="b">
<form action="submit.php" method="post" id="removeBadwordForm" class="ajaxForm" data-action="remove">
<h2>Bad Word Removal</h2>
<label for="advertid" class="select"><h2>Advert:</h2></label>
<select name="badwordid" id="badwordid" data-mini="true"></select>
<input id="removeBadwordButton" name="removebadword" type="submit" value="submit" data-role="button" data-inline="true" data-theme="b" />
</form>
<a href="#admin" class="back"><button data-inline="true">Back</button></a>
<div class="results"></div>
</div>
<!-- End Remove Bad Word-->
<script>
(function(){
function populateDropdown(values, menu, refresh){
makeAjaxRequest(values, function(res){
if (refresh){
$('#' + menu).html(res).selectmenu("refresh")
} else {
$('#' + menu).html(res);
}
});
}
function getFormValues(form){
var $inputs = $('#' + form + ' :input'),
values = {};
$inputs.each(function() {
values[this.name] = this.value;
});
return $.extend(values, {sender: form});
}
function makeAjaxRequest(values, callBack){
$.ajax({
type : "POST",
url : "submit.php",
data: values,
success : function(res) {
callBack(res);
}
});
}
function removeActiveButton(){
$(".ui-btn-active").each(function(){
$(this).removeClass("ui-btn-active");
});
}
$(".ajaxForm").on("submit", function(){
var values = getFormValues(this.id),
action = $(this).data("action"),
selectId = $(this).find("select").attr("id"),
callBack;
if(action === "new"){
callBack = function(res){
$(".results").html(res);
$("input[type=text]").val("");
removeActiveButton();
}
} else {
callBack = function(res){
alert("Operation successful!");
populateDropdown(values, selectId, true);
removeActiveButton();
}
}
makeAjaxRequest(values, callBack)
return false;
});
$(".back").on("click", function(){
$(".results").html("");
});
populateDropdown({sender: "removeSMSForm"}, "smsid", false);
populateDropdown({sender: "removeAdvertForm"}, "advertid", false);
populateDropdown({sender: "removeBadwordForm"}, "badwordid", false);
})()
</script>
</body>
</html>
<?php
try {
$conn = new PDO('mysql:host=localhost;dbname=test', 'root', '*****');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
$sender = $_POST['sender'];
function getLastFive($conn, $table){
$stmt = $conn->prepare("SELECT * FROM $table WHERE content IS NOT NULL AND messagesent = 0 LIMIT 5");
$stmt->execute();
$options = "";
while($row = $stmt->fetch()) {
$options .= "<option value='" . $row["id"] . "'>" . $row["content"] . "</option>";
}
return $options;
}
function delete($conn, $table, $id){
$stmt = $conn->prepare("DELETE FROM $table WHERE id = :id");
$stmt->execute(array('id' => $id));
}
switch($sender){
case "newSMSForm":
$content = $_POST['content'];
$retVal = "A new SMS '" . $content . "' was submitted.";
break;
case "newAdvertForm":
$advert = $_POST['newadvert'];
$retVal = "Advert: '" . $advert . "' has been added to the database.";
break;
case "newBadWordForm":
$badword = $_POST['newbadword'];
$retVal = "Bad word: '" . $badword . "' has been added to the database.";
break;
case "removeSMSForm":
$smsid = $_POST['smsid'];
if (isset($smsid)){
delete($conn, "texts", $smsid);
}
$retVal = getLastFive($conn, "texts");
break;
case "removeAdvertForm":
$advertid = $_POST['advertid'];
if (isset($advertid)){
delete($conn, "adverts", $advertid);
}
$retVal = getLastFive($conn, "adverts");
break;
case "removeBadwordForm":
$badwordid = $_POST['badwordid'];
if (isset($badwordid)){
delete($conn, "badwords", $badwordid);
}
$retVal = getLastFive($conn, "badwords");
break;
}
echo $retVal;
I have updated the JS logic to populate the menus and I have added two generic functions in the PHP to fetch the last five of anything, or to delete something depending on type and id (basically you pass the table as a variable to the function).
I hope this helps you.