When i was going to insert a student in my web app it was showing these error can anyone help me out.
Error Number: 1364
Field 'user_status' doesn't have a default value
INSERT INTO users (first_name, last_name, phone, profile_image, username, password, email, ip_address, created_on, last_login, active) VALUES ('dinesh', 'kumar', '+919591812528', 'fa07b9fc131dc4c7caadac44539c81c4.JPG', 'dinesh kumar', '$2y$08$8KVwr6dQWp8GtsXcFPrRsujqFIBGwdu9MEgMniAXdznXQifCHuDe2', 'dineshprivacy007#gmail.com', '49.207.177.226', 1503992683, 1503992683, 1)
Filename: /home/aspireng/aspiresms/models/ion_auth_model.php
Line Number: 872
user_status Column doesnt have a default value set, kindly set this field NULL as default, and then run query, or insert some value to this field.
if user_status field in your table, please set default value NULL if not assign.
This means there is a user_status column in you db which is expecting some value to be passed in. if you dont have any value to pass then do something like this
INSERT INTO users (first_name, last_name, phone, profile_image, username, password, email, ip_address, created_on, last_login, active,user_status) VALUES ('dinesh', 'kumar', '+919591812528', 'fa07b9fc131dc4c7caadac44539c81c4.JPG', 'dinesh kumar', '$2y$08$8KVwr6dQWp8GtsXcFPrRsujqFIBGwdu9MEgMniAXdznXQifCHuDe2', 'dineshprivacy007#gmail.com', '49.207.177.226', 1503992683, 1503992683, 1,'0')
your field user_status cannot be null so you need to pass any value in it. I just passed 0 for reference.
Related
i am trying to create a user account and i got this error message.
A Database Error Occurred
Error Number: 1048
Column 'group_id' cannot be null
INSERT INTO `bitauth_users` (`username`, `password`, `active`, `activation_code`, `group_id`, `password_last_set`) VALUES ('FAAN', '0884e4e5928d672b182a37b885b5e6ec', 1, '7c6ef5bd05fd2d189df64da76e76017ecec7d233', NULL, '2016-06-23 04:07:08')
Filename: C:\inetpub\vhosts\vidoplus.com\httpdocs\system\database\DB_driver.php
Line Number: 330
Please what do i need to do to fix this. i am new at this. Thanks
As group_id itself suggest that it's a primary key of some table (I think its will be groups table) and treated as a foreign-key in your bitauth_users table.
So you can not pass NULL to it.
You have to pass some value which is related to the table where it is primary key.
Note:- please provide some real value (don't provide empty or 0 etc because at the time of fetching record you will face problem)
Form your error message, you need to give value of group_id (not null value). You can try this:
INSERT INTO bitauth_users (username, password, active, activation_code, group_id, password_last_set) VALUES ('FAAN', '0884e4e5928d672b182a37b885b5e6ec', 1, '7c6ef5bd05fd2d189df64da76e76017ecec7d233', 1, '2016-06-23 04:07:08');
Hope it will help ;)
group_id is not null field ... so if you want to store NULL value then make it nullable other wise you can store 0 or '' blank value.
.
INSERT INTO `bitauth_users` (`username`, `password`, `active`, `activation_code`, `group_id`, `password_last_set`) VALUES ('FAAN', '0884e4e5928d672b182a37b885b5e6ec', 1, '7c6ef5bd05fd2d189df64da76e76017ecec7d233', '', '2016-06-23 04:07:08')
In your sql,tha VALUES part,the group_id is setted to NULL.The error msg is "Column 'group_id' cannot be null".So you can convert NULL to zero.
The sql can be like this:
INSERT INTO `bitauth_users`
(`username`,`password`, `active`, `activation_code`, `group_id`,`password_last_set`)
VALUES
('FAAN', '0884e4e5928d672b182a37b885b5e6ec', 1, '7c6ef5bd05fd2d189df64da76e76017ecec7d233',
0, '2016-06-23 04:07:08')
Hope this can help you!
This is query where i want to insert new data to database. Before this id is auto by using old system and now i make a new form by php. This is my query and now i want make auto increment id.How to make a auto increment id.Please Help me if anyone know.
$sql="INSERT INTO $tbl_name(id, name, icno, email, applyIntake_id, modeOfStudy_id,
choice1_id, dob, nationalityType, gender_id, race_id, highestEducation_id,
address1, address2, postcode, city, state_id, permanent_address1,
permanent_address2, permanent_postcode, permanent_city, permanent_state,
telephoneNo, mobileNo)
VALUES('$name', '$icno', '$email', '$id', '$applyIntake_id', '$modeOfStudy_id',
'$choice1_id', '$dob', '$nationalityType', '$gender_id', '$race_id',
'$highestEducation_id', '$address1', '$address2', '$postcode', '$city',
'$state_id', '$permanent_address1', '$permanent_address2',
'$permanent_postcode', '$permanent_city', '$permanent_state',
'$telephoneNo', '$mobileNo')";
$result=mysql_query($sql);
Try this for MYSQL DB..
ALTER TABLE
`TABLE_SCHEMA`.`TABLE_NAME`
CHANGE COLUMN
`ID` `ID` INT(6) NOT NULL
AUTO_INCREMENT;
Ok, one thing first: you should escape your parameters! See here.
To solve your problem: you can define a field in the database as auto_increment, what will automatically increment the id if left empty.
Amir you have 3 errors in above insert.
The columns count match but you try to insert into #tbl_name(email) value of $id
Please set the id field as autoincrement the answer is in above posts.
I think when preparing PHP $sql variable you have to use "." as string operator to get proper SQL INSERT statement with data from your variables - currently the below INSERT will insert instead of your name variable $name as string into DB.
Exmaple :
$name = 'Tom';
$email = 'tom#o2.pl'
$sql = "insert into table(name,email) VALUES (".$name.",".$email.");";
Then use following insert but apply the example of string join above - it should work:
$sql="INSERT INTO $tbl_name(name, icno, email, applyIntake_id, modeOfStudy_id,
choice1_id, dob, nationalityType, gender_id, race_id, highestEducation_id,
address1, address2, postcode, city, state_id, permanent_address1,
permanent_address2, permanent_postcode, permanent_city, permanent_state,
telephoneNo, mobileNo)
VALUES('$name', '$icno', '$email', '$applyIntake_id', '$modeOfStudy_id',
'$choice1_id', '$dob', '$nationalityType', '$gender_id', '$race_id',
'$highestEducation_id', '$address1', '$address2', '$postcode', '$city',
'$state_id', '$permanent_address1', '$permanent_address2',
'$permanent_postcode', '$permanent_city', '$permanent_state',
'$telephoneNo', '$mobileNo')";
$result=mysql_query($sql);
ALTER TABLE document MODIFY COLUMN document_id INT AUTO_INCREMENT;
There are a couple of reasons that your SQL might not work. First, you must re-specify the data type (INT in this case). Also, the column you are trying to alter must be indexed (it does not have to be the primary key, but usually that is what you would want). Furthermore, there can only be one AUTO_INCREMENT column for each table. So, you may wish to run the following SQL (if your column is not indexed):
ALTER TABLE document MODIFY document_id INT AUTO_INCREMENT PRIMARY KEY;
You can find more information in the MySQL documentation: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html for the modify column syntax and http://dev.mysql.com/doc/refman/5.1/en/create-table.html for more information about specifying columns.
I am trying to insert data into a table (table1) based on another (table2), the only problem is that table1 contains fields set to not allow null values. Do I need to create these fields in table2 where I am pulling the data from and populate them with a value?
Example not null field: password
If I do not include this in my query then I get an error and the record is not inserted however if I create the field in table2 then insert into my query it works fine. This seems a bit out of the ordinary. Example query below:
Example 1 (no password field in table 2):
$insert_new_records_query = "INSERT INTO table1 (first_name, last_name, email_address) ".
"SELECT firstname, lastname, email FROM table2";
This generates an error saying that I must include the password field.
Example 2 (password field in table 2):
$insert_new_records_query = "INSERT INTO table1 (first_name, last_name, password,
email_address) ".
"SELECT firstname, lastname, password = 'password1', email FROM table2";
This allows the record to be created. The problem is that I have many more fields that are not null in table 1 and I don't think I need to create them in table 2 as blank fields and insert them into my query with values just to create a record. Is there a better way to do this?
You don't have to create fields, you can simply 'select' default values. Try this instead:
INSERT INTO table1 (first_name, last_name, password, email_address)
SELECT firstname, lastname, 'password1', email FROM table2
I have a PHP loop that's auto-generating an array to INSERT into a table. But I get this error:
Database query failed: Incorrect integer value: '' for column 'id' at row 1
Last SQL query: INSERT INTO users(id, email, password, first_name, last_name) VALUES ('', 'test#user.com', 'fljhdsfsd', 'John', 'Doe')
I've tried setting the id field as No Null and Null, but that didn't help.
Any ideas? Thanks in advance for your help.
If your id field is an auto-incremented column then you can simply omit it from the INSERT query.
INSERT INTO users(email, password, first_name, last_name)
VALUES ('test#user.com', 'fljhdsfsd', 'John', 'Doe');
An id will be generated automatically.
Your Mysql is running in the strict mode. You have to pass the NULL if you have no value for that column, if the column is auto increment you can keep out this column from query.
Once try the below query, I believe this will work.
INSERT INTO users(id, email, password, first_name, last_name)
VALUES (NULL, 'test#user.com', 'fljhdsfsd', 'John', 'Doe')
If id field is auto incremented you can skip that field. If not then read error, it says "Incorrect integer value" and you are giving '' witch is string. In this case before every insert you should fetch max id from database and increment it, or use any other ID generation.
This is happened because your id field in database now contains only integer value. and blanck is not a integer value. Just change the data type on your database.
Just change your datatype id "integer" to "varchar", tick out the "auto increment" and put a length like "250" field in database, then run your query.
I have a table with one field of enum type. I execute the following query using pg_query
INSERT INTO users (email, facebook_id, first_name, middle_name, last_name, birth_date, password, gender, school_id, timezone, email_verified, role_id) VALUES ('robert#1599309412.com', NULL, 'Robert', '', 'George', '1984-05-20', 'Some password', 'MALE', 1, '0.0', false, 1 );
pg_query($connection, 'INSERT INTO users (email, facebook_id, first_name, middle_name, last_name, birth_date, password, gender, school_id, timezone, email_verified, role_id) VALUES (\'robert#2084537193.com\', NULL, \'Robert\', \'\', \'George\', \'1984-05-20\', \'Some password\', \'MALE\', 1, \'0.0\', false, 1 )')
but i get error as below.
PHP Warning: pg_query(): Query failed: ERROR: invalid input value for enum sex: "MALE"
LINE 1: ...rt', '', 'George', '1984-05-20', 'Some password', 'MALE', 1,...
Direct execution of query in postgres client don't give this error.What is solution for this?
Please make sure cases match. Postgres is not too strict about it (consider the table names), but it might worth a check.
Having a gender attribute enum'd is unnecessary overhead in my opinion, you're better off having a male int column with 1, 0 values and maybe null for unknown/not specified. With values greater than 1 it's still future-proof just in case a new gender appears. :)
If you really are attached to enums, you might want to consider using PDO, because it makes binding values a lot easier and a lot more secure.