使用PHP将数据插入数据库时出错
我正在尝试从我创建的数据库中插入一个简单联系人表单中的数据。我用的是phpMyAdmin 这是PHP(出于安全原因,我删除了define语句,但我能够毫无问题地建立到数据库的链接。) 我的数据库/表设置如下 数据库名称=phpmy1\u belairfinishing\u com 表名=联系人 列名与insert语句中的列名完全相同 任何帮助都将不胜感激 编辑:这是表格结构,如果有帮助的话 列类型使用PHP将数据插入数据库时出错,php,database,Php,Database,我正在尝试从我创建的数据库中插入一个简单联系人表单中的数据。我用的是phpMyAdmin 这是PHP(出于安全原因,我删除了define语句,但我能够毫无问题地建立到数据库的链接。) 我的数据库/表设置如下 数据库名称=phpmy1\u belairfinishing\u com 表名=联系人 列名与insert语句中的列名完全相同 任何帮助都将不胜感激 编辑:这是表格结构,如果有帮助的话 列类型 ID tinyint(4) FName varchar(75) LName varchar(75)
ID tinyint(4)
FName varchar(75)
LName varchar(75)
电话接口(11)
街道文字
城市文本
状态文本
国家/地区文本
Zipcode int(10)
电子邮件varchar(75)
消息文本 我试图输入的值是 无效的 提姆 猛打 111-111-1111 1随机街 随机城市 随机状态 美国 randomemail@gmail.com
随机信息顺便说一句,只是一个想法 您不使用mysqli\u stmt\u bind\u参数 但是使用mysqli\u real\u escape\u字符串 清理vlues(但mysqli_stmt_bind_param确实是更好的实践) 因此,请在文档中查看此通知:
**Caution**
Security: the default character set
The character set must be set either at the server level, or with the API function mysql_set_charset() for it to affect mysql_real_escape_string(). See the concepts section on character sets for more information.
您正在混合mysql和mysqli。您需要使用mysqli_error()。将这两个错误都更改为mysqli.error(),但仍然没有收到错误消息。die('SLQ Insert语句失败:'.mysql_error().''。$sqlInsert)然后粘贴Insert语句查找mysqli的prepare方法。使用预先准备好的语句要比多次调用
mysqli\u real\u escape\u string
容易得多。而且它会更安全,因为mysqli\u real\u escape\u string
并不完美,也不会总是阻止SQL注入。它是mysqli\u error()
,而不是mysqli.error()
。您必须将$link
作为参数传递。阅读mysqli_stmt_bind_参数,我将更改php以使用该参数,而不是mysqli_real_escape_字符串,并查看是否修复了任何问题。请查看您问题下的最后一条评论
if(!mysqli_real_query($link, $sqlInsert)){
die('SLQ Insert Statement Failed: ' . mysql_error());
}
**Caution**
Security: the default character set
The character set must be set either at the server level, or with the API function mysql_set_charset() for it to affect mysql_real_escape_string(). See the concepts section on character sets for more information.