Do I need to create columns in phpmyadmin for every checkbox I created?

Asked

Viewed 170 times

-1

I’m creating a hotel website for a school project, and I’d like to know if for each checkbox that I created in the code, I will have to create a column in the database of the phpmyadmin? And how to store this choice of checkbox there in the database?

Note: I am using the xampp

<div id="quartos">
       <div id="junior"> <input type="checkbox" name="quarto[]" value="op1"/> Suíte Júnior<br /></div>
       <div id="duplo"> <input type="checkbox" name="quarto[]" value="op2"/> Quarto Solteiro Duplo<br /></div>
       <div id="casal1"> <input type="checkbox" name="quarto[]" value="op3"/> Quarto Casal<br /></div>
       <div id="vista"> <input type="checkbox" name="quarto[]" value="op4"/> Apartamento Luxo vista para a cidade <br /></div>
       <div id="luxo1"> <input type="checkbox" name="quarto[]" value="op5"/> Apartamento Luxo <br /></div>
       <div id="master1"> <input type="checkbox" name="quarto[]" value="op6"/> Suíte Master <br /></div>
</div>

  • In this case, I would suggest using radio button, because the room can only be an option (or not?), and make a column TIPO_QUARTO for example.

  • Create columns or insert data into table columns?

  • @Rafaelweber switched to radio burron and created the room type column. What do now ?

  • The options you put in div id="quartos". The user can only select one option, correct?

  • Well, you can follow what you have on [link] (https://wiki.locaweb.com.br/pt-br/Formul%C3%A1rio_php_%2B_Mysql)

  • @Djalmamanfrin yes

Show 1 more comment

1 answer

1

What will decide how the data will be saved in the database will be the Entity and Relationship Model (MER) prepared. As mentioned in the question, you have created a website aimed at the hospitality industry. And as the following example, we can observe a MER in the hospitality industry.

Note that the guest has a relationship with the reservation, which in turn with the room and the room with the room guy.

inserir a descrição da imagem aqui

In the image below who drew the MER indicated that the way to store the type of the room will be through the relation, where: 1 room has 0 or 1 room type. And the room type can contain in 1 or n(more) rooms.

inserir a descrição da imagem aqui

Your question is, how should I save the type of room chosen by the guest? A: Following the logic of this MER, the table quarto will have a Foreign key table tipo_quarto. That is, you can follow this concept and create a table tipo_quarto, and every time the guest book a room, you will save the id or codigo, according to MER, table tipo_quarto on the table quarto.

It would be more interesting to use a select containing the options of the room types and for each <option> id. But if you want to continue with div's, for each value="" of <input/> must contain an id.

Then follow the logic given. You do not need to create a column in the database for each tipo_quarto. If you have more questions just comment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.