我正在从数据库中提取信息并将其放入选择字段中。在选择字段中,它看起来是完整的,但在重新插入数据库时,初始空格之后的任何单词都会被删除。
这是我的代码:
<?
require_once('./inc/glob_head.php');
if (isset($_POST['submitNewOther']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
try {
$checkDB = $database->prepare('SELECT * FROM mainSite_others WHERE forGame=:fg AND otherType=:ot AND otherName=:otn');
$addToDB = $database->prepare('INSERT INTO mainSite_others(forGame,otherType,otherName,otherDesc,otherCost,membeOnly,otherPageContent) VALUES (:fg,:ot,:otn,:od,:oc,:mo,:opc)');
} catch (PDOException $e) {
error_log($e->getMessage());
exit();
}
$checkDB->execute(array(':fg'=>$_POST['forGame'],':ot'=>$_POST['otherType'],':otn'=>$_POST['otherName']));
if ($checkDB->rowCount() == 0) {
try {
$addToDB->execute(array(':fg'=>$_POST['forGame'],':ot'=>$_POST['otherType'],':otn'=>$_POST['otherName'],':od'=>$_POST['otherDesc'],':oc'=>$_POST['otherCost'],':mo'=>$_POST['membeOnly'],':opc'=>$_POST['otherPageContent']));
redir('addOther.php?action=success');
} catch (PDOException $e) {
error_log($e->getMessage());
exit();
}
} else {
echo "Other already in database";
}
} elseif (isset($_GET) && $_GET['action'] == 'success') {
?>
<h2>"Other" added to database.</h2>
<h4><a href='addOther.php'>Add another</a> or choose something new to do.</h4>
<?
} else {
?>
<fieldset>
<legend><h2>Add other</h2></legend>
<form name='addOther' id='addOther' method='POST'>
<select name='forGame'>
<?
try {
$listOfGames = $database->prepare('SELECT * FROM mainSite_games');
$listOfGames->execute();
$games = $listOfGames->fetchAll(PDO::FETCH_ASSOC);
foreach ($games as $game) {
print '<option value='.$game['gameName'].'>'.$game['gameName'].'</option>';
}
} catch (PDOException $e) {
error_log($e->getMessage());
exit();
}
?>
</select><br />
<select name='otherType'>
<option value='Item'>Item</option>
<option value='Place'>Place</option>
<option value='Character'>Character</option>
</select><br />
<input type='text' name='otherName' placeholder='Other name' required /><br />
<input type='text' name='otherDesc' placeholder='Other examine (or NA)' required /><br />
<input type='text' name='otherCost' placeholder='Other cost (price/NA)' required /><br />
<input type='text' name='membeOnly' placeholder='Members Only (Yes/No)' required /><br />
<textarea name="otherPageContent" class="span12" rows="10" placeholder="Other page content" required></textarea><br />
<input type='submit' name='submitNewOther' class='btn btn-primary' /><br />
</form>
</fieldset>
</div>
</div>
</div>
</body>
</html>
<?
}
$database = null;
?>
底部(纯 html 部分)是它从数据库中拉出的地方——第一个选择是它被放置的地方。观看时是完整的:
现在,当提交此表单时,它成功进入数据库,但显示为 - 因此破坏了我的网站(现在允许用户查看此游戏内容,因为据它所知,游戏的数据库/任务不存在(它正在检查整个名称)。这就是它在 SQL 管理员中的样子:
RuneScape 很好(因为我猜没有空格?)但是 Carnage 应该是 Carnage Racing。
我的代码有问题导致这个吗?这不是它发生的唯一页面,但我想如果我找到源代码,我可以在所有页面上修复它。
redir() 是一个自定义函数,它使用 JS 来 redir,这样我就不必玩标题了