我已经检查了关于同一主题的其他类似问题,但是即使经过这些问题,我也找不到我的代码有什么问题。
1)我上周在单页php文件上使用了相同的代码,并且可以正常工作。我现在将文件拆分为多个php文件,从理论上讲应该没有任何影响。2)我收到的错误对我来说真的很奇怪。当我使用“ Sally Test”作为名称,“ [email protected]”作为电子邮件并使用“ testing 123”作为评论输入评论时,出现此错误:
“您的SQL语法有误;请查看与您的MySQL服务器版本相对应的手册,以找到正确的语法,以在'(作者,电子邮件,ip
date
、、边,类别,modscore,内容)VALUES('Sally T'在第1行“
它会将“ Sally测试”截短为“ Sally 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内容,因此从长远来看,我确实打算替换所有这些。但是现在,我想修复代码。提前致谢!
这不是在“截断”用户名;而是“删除”用户名。只是错误消息仅包含查询的一部分,从发现问题的那一部分开始。引用的部分恰好在T
in之后结束Test
。
实际的问题似乎是您从未设置$myname_sqltable
表的名称,因此查询以just开头INSERT INTO (author, email,
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句