我遇到了更新包含HTML數據的我的MySQL數據的問題,我不斷修正錯誤;但是,一旦一個錯誤得到解決,就會給出另一個錯誤。當前的錯誤如下:PHP包含關鍵字/保留字的MySQL查詢
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='Live updates to certain games will also be posted on this website througho' at line 1
我一直在清除堆棧溢出了近3天沒有任何明確的答案。所以我希望有人能找到這個!
這裏是我的PHP表單代碼:
if (isset($_POST['submit'])) {
$WName = mysql_prep($_POST['wname']);
$SName = mysql_prep($_POST['sname']);
$Desc = mysql_prep($_POST['desc']);
$LogoURL = mysql_prep($_POST['logourl']);
$aboutPage = mysql_prep($_POST['aboutpage']);
$query = "UPDATE settings SET name='$WName',subName='$SName',desc='$Desc',logoUrl='$LogoURL',about='$aboutPage'";
// $query = mysql_prep($query);
mysql_query($query) or die(mysql_error());
header("Location: settings.php?=success");
}
功能
mysql_prep()可以在互聯網,即在這裏找到: https://gist.github.com/ZachMoreno/1504031
下面是HTML表單:
<form role="form" action="" method="post">
<!-- text input -->
<div class="form-group">
<label>Website Name</label>
<input type="text" name="wname" class="form-control" placeholder="
<?php echo $row['name']; ?>" value="
<?php echo $row['name']; ?>" />
</div>
<div class="form-group">
<label>Sub Name</label>
<input type="text" name="sname" class="form-control" placeholder="
<?php echo $row['subName']; ?>" value="
<?php echo $row['subName']; ?>" />
</div>
<div class="form-group">
<label>Description</label>
<textarea name="desc" class="form-control" rows="3" placeholder="
<?php echo $row['desc']; ?>" >
<?php echo $row['desc']; ?>
</textarea>
</div>
<div class="form-group">
<label>Logo URL</label>
<input type="text" name="logourl" class="form-control" placeholder="
<?php echo $row['logoUrl']; ?>" value="
<?php echo $row['logoUrl']; ?>" />
</div>
<div class="form-group">
<label>About Page</label>
<textarea class="form-control" name="aboutpage" rows="6" placeholder="
<?php echo $row['about']; ?>">
<?php echo $row['about']; ?>
</textarea>
</div>
<div class="box-footer">
<input type="submit" name="submit" class="btn btn-primary" value="Submit" style="margin-left:-10px;" />
</div>
</form>
謝謝非常希望你能提供任何幫助,我希望能夠解決這個問題,並且我的目標是用來幫助未來的訪問者相同/相似的問題。
應該使用mysqli_函數和mysqli_real_escape_string()函數,而不是舊的,不推薦使用的mysql_函數。 – SyntaxLAMP
你可以var_dump($ query)'併發布結果 – MaggsWeb
如何使用'htmlspecialchars()'和'mysqli_real_escape_string()'? – Thamilan