G
G
GeKskill2020-05-03 10:33:36
MySQL
GeKskill, 2020-05-03 10:33:36

DB data record in a column?

There are tables:
users -> id | login | password ,
users_meta -> id | users_id | meta key | meta_value (such a structure is used in WordPress)

And there is a form with fields (First Name , Last Name, Email, Notes ).
How to insert data into users_meta when submitting a form, where meta_key = input name, and meta_value corresponds to the value of the input field. And how to extract data from such a structure later: SELECT * FROM `users_meta` WHERE user_id = "1" (how to display only First Name and Email)

According to the conclusion, I realized that you can throw everything into an array and get it by key ... The question remains how to bring in basis, too a cycle somehow?
PS I will try this. Does it heavily load the base?

foreach ($_POST as $key => $value) {     
  $query = query("INSERT INTO `users_meta` (user_id,meta_key, meta_value) VALUES('$user_id','$key', '$value')");  
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentyn, 2020-05-03
@GeKskill

For inserting with PHP should help:
PDO: Prepared multi-inserts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question