我无法将数据插入MySQL数据库
DROP TABLE IF EXISTS `register`;
CREATE TABLE `register` (
`id` int(11) NOT NULL,
`username` varchar(100) NOT NULL,
`unique_code` varchar(300) NOT NULL,
`email` varchar(300) NOT NULL,
`name` varchar(300) NOT NULL,
`mobile` varchar(200) NOT NULL,
`address` longtext NOT NULL,
`state` varchar(50) NOT NULL,
`country` varchar(50) NOT NULL,
`zipcode` varchar(50) NOT NULL,
`city` varchar(200) NOT NULL,
`password` varchar(300) NOT NULL,
`temp_password` varchar(300) NOT NULL,
`image` varchar(300) NOT NULL,
`phone_verified` int(11) NOT NULL,
`reg_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` int(11) NOT NULL,
`gcm_code` longtext NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)
当我尝试注册时,出现此错误,并且在msql表中未添加任何数据。
INSERT INTO register (
username,
mobile,
password,
temp_password,
email,
status
)
VALUES (
"user",
"1234678",
"202cb962ac59075b964b07152d234b70",
"123",
"admin@admin.com",
""
)
Error in query.
Run Code Online (Sandbox Code Playgroud)
这是我的MySQL数据库连接文件
define('DIRECT_ACCESS', true);
define('HOST','localhost');
define('DATABASE','id9346797_market');
define('USERNAME','idxxxxxxxxxxxx');
define('PASSWORD','xxxxxxxx');
define('DB_PREFIX','');
define('SITE_URL', (@$_SERVER['HTTPS'] ? "https" : "http") . "://" . $_SERVER['HTTP_HOST']."/fruitmarket/");
Run Code Online (Sandbox Code Playgroud)
如果有人解决了这个问题,我将不胜感激。
更新: 我将上一张表更改为此。
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`username` varchar(60) NOT NULL,
`mobile` varchar(60) NOT NULL,
`password` varchar(60) NOT NULL,
`email` varchar(255) NOT NULL,
`active` tinyint(4) NOT NULL,
`type` varchar(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)
并更改mysql数据库的最后一行
由此
define('SITE_URL', (@$_SERVER['HTTPS'] ? "https" : "http") . "://" . $_SERVER['HTTP_HOST']."/fruitmarket/");
Run Code Online (Sandbox Code Playgroud)
对此
define('SITE_URL','http://localhost/fruitmarket/');
Run Code Online (Sandbox Code Playgroud)
我仍然遇到相同的错误。
这是注册表
<?php common::user_access_only("admin");
if(isset($_POST['submit']))
{
form_validation::add_validation('username', 'required', 'Registration Name');
form_validation::add_validation('username', 'no_space', 'Registration Name');
form_validation::add_validation('mobile', 'required', 'mobile');
form_validation::add_validation('email', 'required', 'Registration email');
form_validation::add_validation('email', 'email', 'Registration email not valid');
form_validation::add_validation('password', 'required', 'Registration Passowrd');
form_validation::add_validation('password', 'no_space', 'Registration Passowrd');
if(form_validation::validate_fields())
{
$username=common::get_control_value("username");
$mobile = common::get_control_value("mobile");
$password=common::get_control_value("password");
$email=common::get_control_value("email");
$active = common::get_control_value("status");
$q = new Query();
$q->insert_into("register",array("username"=>$username,"mobile"=>$mobile,"password"=>md5($password),"temp_password"=>$password,"email"=>$email,"status"=>$active))
->show()
->run();
common::set_message(3);
common::redirect_to(common::get_component_link(array("appuser","list")));
}
}
?>
Run Code Online (Sandbox Code Playgroud)
错误消息对您不利,这是MySQL返回的全部内容吗?
您的表中有大量字段,它们定义为NOT NULL并且没有默认约束。但是您的INSERT查询未指定所有值。您需要执行以下一项(或多项):
INSERT 表中所有字段的值NOT NULL字段创建默认约束NULL