Problem: I have a table categories on my database which contains the cat_id as primary key of type int and cat_name as name of the category. But I collect info from the under via radio.
Question: How can I convert the 'on' and 'off' from the user to integers?
Error Given:
Illuminate\Database\QueryException SQLSTATE[HY000]: General error:
1366 Incorrect integer value: 'on' for column 'type' at row 1 (SQL:
insert into users (user_name, name, type, email, password,
updated_at, created_at) values (malico, John Doe, on,
john.doe#gmail.com,
$2y$10$yyf4Vt01ukTNPFxGa1PIheJZvmcPbozGjdz8zo84vkK325Qk6rfna,
2018-05-19 12:56:01, 2018-05-19 12:56:01))
just do something like this on your request :
$request->merge(['type'=>$request->get('type') == 'on' ? 1 : 0]);
this will change "on" to 1 in your request
Related
SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL: insert into product_catagories (catagory_name, updated_at, created_at) values (Electronics, 2021-04-25 14:32:59, 2021-04-25 14:32:59))
How Can I solved this problem on a live server
Check your 'id' structure on your sql.
You got an error because 'id' field' doesn't have default value.
Also Make sure AUTO_INCREMENT checked
I am trying to insert postal codes from one table(insert into pre-existing rows) to another table of addresses that have null postal codes. The address_id in postalcodes corresponds to the address_id in address table.
The postal codes table has the address_id and postalcode.
Here is the postal codes table:
Here is the address table:
This is what I have tried.
INSERT INTO address ( postal_code )
SELECT
postalcodes.postalcode
FROM
postalcodes
WHERE
address.address_id = postalcodes.address_id;
But it gives me an error:
Error starting at line : 26 in command -
INSERT INTO address ( postal_code )
SELECT
postalcodes.postalcode
FROM
postalcodes
WHERE
address.address_id = postalcodes.address_id
Error at Command Line : 32 Column : 9
Error report -
SQL Error: ORA-00904: "ADDRESS"."ADDRESS_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
You want an update, not an insert:
UPDATE address
SET postal_code = (SELECT p.postal_code
FROM postalcodes p
WHERE a.address_id = p.address_id
)
WHERE postal_code IS NULL;
You need to insert the rest of the values for address. You can't insert postal codes by themselves. Or are you trying to update the values of zipcodes for existing addresses?. Creating zip codes into address will give you NULL, NULL, NULL, ZIP_CODE, NULL, ECT. IF it doesnt give you an error based on some primary key constrain
Maybe trying selecting
FROM
postalcodes, Address
SQL hAs no ida what address is unless you select from it.
I am doing a basic project in Laravel, when trying to delete an entry, it generates this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from `employees` where `id` = 6 limit 1)
and it is true I don't have a column named 'id', instead I have employee_id, but why is it choosing id instead of employee_id?
Please explain from where did it bring this id column?
In your Employee model (Employee.php), add
protected $primaryKey = 'employee_id';
This will tell Laravel to use employee_id as the primary key for Empolyee objects.
I have wierd trouble during validating request in controller. I use exists validation rule. User is supposed to submit integer. This integer should exist as id in a single row of user_courses table. This row also should have column user_id equal to 158 - docs.
My validation rule:
'course_id' => 'integer|exists: user_courses, id, user_id, 158'
What I got instead:
PDOException in Connection.php line 333: SQLSTATE[42S22]: Column not
found: 1054 Unknown column ' id' in 'where clause'
My Table:
id, user_id, created_at, updated_at
Problem was in the spaces:
'course_id' => 'integer|exists: user_courses, id, user_id, 158' // incorrect
'course_id' => 'integer|exists:user_courses,id,user_id,158' // correct
Original code would confuse laravel to search for column names like this:
' user_courses'
Well, i need to add a row in user_badges for each person who had correctly respond to a poll. The
"select user_id from room_poll_results........" is working fine alone, but as soon as i try to use it in my INSERT INTO statement, it gives back an error:
"[Err] 1054 - Unknown column 'user_id' in 'IN/ALL/ANY subquery'"
I don't know where it's coming from...
INSERT INTO user_badges (user_id,PPO) SELECT user_id IN
(SELECT user_id FROM room_poll_results
WHERE user_id in (select user_id from room_poll_results
where answer_text='3' AND question_id='3') AND user_id in
(select user_id from room_poll_results where answer_text='2' AND question_id='4'));
It's telling you that there's no column called user_id in room_poll_results. Change that column name (in the subselects) to whatever is the appropriate field in the table. (You'd want to post the full schema for a more specific response.)
Whenever you get errors as "[Err] 1054 - Unknown column 'user_id' in 'IN/ALL/ANY subquery'" just read it to mean that a COLUMN with the give name in parenthesis does not exist in your query.
To debug this, since you are have sub-queries, run each query independently then see their results. That will help you know what table has the missing column. Once you've got it then you can create the column and then unite your sub-queries and that's it!
I assume user_badges table has a column user_id. Your first IN should be replaced by FROM. So, I've slightly modified your query as below:
INSERT INTO user_badges (user_id, PPO)
SELECT user_id FROM
(
SELECT user_id FROM room_poll_results
WHERE user_id in
(
select user_id from room_poll_results
where answer_text='3' AND question_id='3'
) AS U
AND user_id in
(
select user_id from room_poll_results
where answer_text='2' AND question_id='4'
) AS U
) AS U;