我已经检查了同一主题上的其他类似问题,但即使经历过这些问题,我也无法找到我的代码有什么问题。
1)我上周在一个单页的php文件中使用了相同的代码并且它有效。我现在已将文件拆分为多个php文件,理论上应该没有任何影响。 2)我收到的错误真的很奇怪(对我来说)。当我使用" Sally Test"输入评论时作为名称," Sally@test.com"作为电子邮件和"测试123"作为评论,我收到了这个错误:
"您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'(作者,电子邮件,IP,
date
,侧面,类别,modscore,内容) 价值观(' Sally T'第1行和第34行;
它会截断" Sally Test"只是"莎莉T"我不知道为什么会这样。
这是我的数据库处理代码(我使用Dreamweaver):
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if (isset($_POST["MM_insert"])) {
$insertSQL = sprintf("INSERT INTO " . $myname_sqltable ." (author, email, ip, `date`, side, category, modscore, content) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['author'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['ip'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['side'], "text"),
GetSQLValueString($_POST['category'], "text"),
GetSQLValueString($_POST['modscore'], "int"),
GetSQLValueString($_POST['content'], "text"));
mysql_select_db($database_commenting_conn, $commenting_conn);
$Result1 = mysql_query($insertSQL, $commenting_conn) or die(mysql_error());
}
这是表单代码:
<form class="form-horizontal" role="form" method="post" name="contribute_form_side1-row0" action="/mozilla/index.php?">
<div class="form-group">
<label class="sr-only" for="author">Name</label>
<input type="text" name="author" class="form-control" id="name_input_side1-row0" placeholder="Your Name">
</div>
<div class="form-group">
<label class="sr-only" for="email">Email</label>
<input type="email" name="email" class="form-control" id="email_input_side1-row0" placeholder="Your Email Address">
</div>
<div class="form-group">
<label class="sr-only" for="Content Input">Viewpoint</label>
<textarea class="form-control" name="content" id="content_input_side1-row0" rows="3" placeholder="Your perspective"></textarea>
</div>
<input type="hidden" name="ip" value="**deleted**">
<input type="hidden" name="date" value="2014-04-18 14:51:57">
<input type="hidden" name="MM_insert" value="contribute_form_side1-row0">
<input type="hidden" name="side" value="">
<input type="hidden" name="category" value="0">
<input type="hidden" name="modscore" value="0">
<button type="submit" class="btn btn-success btn-block">Submit</button>
</form>
为什么它会截断用户的姓氏(也会出现其他名称)以及为什么表单提交不再有效?我在单页版本上使用了几乎重复的代码。
我现在也在学习sqli的东西,所以从长远来看,我打算更换所有这些。但是现在,我想修复代码。提前谢谢!
答案 0 :(得分:0)
它不是&#34;截断&#34;用户名;只是错误消息只包含查询的一部分,从它注意到问题的部分开始。引用的部分恰好在T
中的Test
之后结束。
实际问题似乎是您从未将$myname_sqltable
设置为表格的名称,因此您的查询仅以INSERT INTO (author, email,
开头。