【发布时间】:2016-02-02 02:23:54
【问题描述】:
我在更新包含 HTML 数据的 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
我在 Stack Overflow 上搜索了将近 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_ 函数。
-
你能
var_dump($query)并发布结果 -
使用
htmlspecialchars()和mysqli_real_escape_string()怎么样? -
不幸的是,这个项目被要求使用旧的不推荐使用的 MySQL。 @MaggsWeb,我现在就这样做。