diff --git a/includes/titleranks-add.php b/includes/titleranks-add.php
index a9655a1..214bbbd 100644
--- a/includes/titleranks-add.php
+++ b/includes/titleranks-add.php
@@ -17,7 +17,19 @@ if (isset($_SESSION['tid'])) {
if (isset($_SESSION['tr'])) {
$tr = $_SESSION['tr'] + 1;
} else {
- $tr = 0;
+ $trank = $con->prepare("SELECT MAX(strank) FROM gwsubtitles WHERE titlenameid = ?");
+ $trank->bind_param("i", $_POST['tid']);
+ $trank->execute();
+ $trank->store_result();
+ $trank->bind_result($gwstmr);
+ while ($trank->fetch()) {
+ if (is_null($gwstmr)) {
+ $tr = 1;
+ } else {
+ $tr = $gwstmr;
+ echo 'variable tr is set to: ' . $tr . '
';
+ }
+ }
}
$stmtname = $con->prepare("SELECT titlename, titlemaxrank FROM gwtitles WHERE titlenameid = ?");
diff --git a/titlemanager.php b/titlemanager.php
index 25d3f03..188c356 100644
--- a/titlemanager.php
+++ b/titlemanager.php
@@ -35,10 +35,10 @@ if ($_SESSION['admin'] == 1) {
} else {
unset($_SESSION['tid']);
echo 'Add titles