I have an html drop down with some values like :
This one is inside form :
<b>Priority</b><select><name = "priority" id="priority"><option>Low</option><option>Medium </option><option>High</option></select>
Now when I click submit, What the value I select should be inserted to db. For that iadded like :
$priority = $_POST['priority'];
$sql3= "INSERT INTO work (priority) VALUES ('$priority')";
But it throw error : unknown identifier.
So how can I get the value from the select and insert into db. Pleasehelp
Change:
<select><name = "priority" id="priority">
to:
<select name="priority" id="priority">
Related
I have a form with a series of checkboxes. The name of the checkboxes is name="groups[]".
<input type="checkbox" name="groups[]" value="value-1">
<input type="checkbox" name="groups[]" value="value-2">
<input type="checkbox" name="groups[]" value="value-3">
<input type="checkbox" name="groups[]" value="value-4">
I want to save the values submitted to a column named groups in a MySQL database. My Laravel update code is as follows:
$record->groups = $attributes['groups'];
$record->save();
I have also tried:
$record->groups = implode(',', $attributes['groups']);
$record->save();
Just in case it helps, the field details in the migration file is:
$table->set('groups', ['value-1','value-2','value-3','value-4'])->nullable();
The error receiving is:
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'groups' at row 1 (SQL: update `table` set `groups` = ["value-1","value-2"] where `id` = 1)
Is my update code incorrect for Laravel and Set columns?
I tried Googling a lot, but because the term set is used in regular update queries, I'm not getting helpful results.
Edit: Added Table Structure
Column
Type
id
bigint(20)
groups
set('value-1','value2','value-3','value-4')
Edit: Results of my attributes:
array: 1 [▼
"groups" => array:2 [▼
0 => "value-1"
1 => "value-2"
]
]
'''
It ends up that the correct method to update a set type column is to implode the array into a comma separated string. I thought I tried this earlier, but it's working now, not actually sure why it wasn't before and is now. Here is the working update:
$proposal->groups = implode(',', $attributes['groups']);
$proposal->save();
I have a column in my table containing a JSON statuses_json:
{
"demoStatus" : "true",
"productionStatus": "false"
}
I would like to retrieve a value where the key is LIKE some string.
For example, if I pass in "demo", I want to retrieve the value for the key demoStatus.
Right now I am able to retrieve values when passing the exact key:
`statuses_json->>'productionStatus' = 'false' `;
Extract the keys and run a query on it:
select *
from json_object_keys('{
"demoStatus" : "true",
"productionStatus": "false"
}') k where k like '%demo%';
I don't have a new enough version of postgresql but jsonb_path_query looks interesting, too. Then used statuses_json->>(...) to extract the corresponding value(s).
select statuses_json from your_table
where statuses_json->>(
select prop
from json_object_keys(statuses_json) as prop
where prop like 'demo%'
) = 'false';
I've been trying to use dynamic columns with an instance of MariaDB v10.1.12.
First, I send the following query:
INSERT INTO savedDisplays (user, name, body, dataSource, params) VALUES ('Marty', 'Hey', 'Hoy', 'temp', COLUMN_CREATE('type', 'tab', 'col0', 'champions', 'col1', 'averageResults'));
Where params' type was defined as a blob, just like the documentation suggests.
The query is accepted, the table updated. If I COLUMN_CHECK the results, it tells me it's fine.
But when I try to select:
"SELECT COLUMN_JSON(params) AS params FROM savedDisplays;
I get a {type: "Buffer", data: Array} containing binary returned to me, instead of the {"type":"tab", "col0":"champions", "col1":"averageResults"} I expect.
EDIT: I can use COLUMN_GET just fine, but I need every column inside the params field, and I need to check the type property first to know what kind of and how many columns there are in the JSON / params field. I could probably make it work still, but that would require multiple queries, as opposed to only one.
Any ideas?
Try:
SELECT CONVERT(COLUMN_JSON(params) USING utf8) AS params FROM savedDisplays
In MariaDB 10 this works at every table:
SELECT CONVERT(COLUMN_JSON(COLUMN_CREATE('t', text, 'v', value)) USING utf8)
as json FROM test WHERE 1 AND value LIKE '%12345%' LIMIT 10;
output in node.js
[ TextRow { json: '{"t":"test text","v":"0.5339044212345805"}' } ]
I have a live template like this
<div>$name$: $id$</div>
Now I want to set the default value of $id$ to name + "_id".
But when I put the default value of $id$ as name + "_id", in the "Edit Template Variables Dialog", the autocomplete does not concatenate value of name and (string) "_id" together. It only uses the value of name and ignored the "_id" part (for default value of $id$).
How can I make the default value of $id$ as name + "_id" in my live templates?
You can try to create a variable and concat the values into it.
Something like:
#set( $your_var = $NAME + '_id')
<div>$name$: $your_var$</div>
Not sure about phpstorm, but I was just looking for the solution to this problem in webstorm and there is a concat(expressions...) function. So, solution to the problem could be to put in the 'Expression' field:
concat(name,"_id")
You can just do this:
<div>$name$: $name$_id</div>
I want to query string from a field from my database. For example: Field "Address", value "Toul Kork District, Phnom Penh". Want I want to get is only "Phnom Penh". I know that my sql is not allow to select only this string from the field. So, what is the good way to do that?
This may help you :
SELECT SUBSTR(Address,
LOCATE(Value,Address),
LENGTH(Address) - LENGTH(Value));
POSITION function is synonim for LOCATE. You can use POSITION function as well :
SELECT SUBSTR(Address,
LOCATE(Value IN Address),
LENGTH(Address) - LENGTH(Value));
In static variable it's looks like :
SELECT SUBSTR('Toul Kork District,Phnom Penh',
LOCATE('Phnom Penh','Toul Kork District,Phnom Penh'),
LENGTH('Toul Kork District,Phnom Penh') - LENGTH('Phnom Penh'));
Result : Phnom Penh