0

after form submission, the data is stored in database. This is the query i already have:

CREATE TABLE IF NOT EXISTS `registered_users` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`gender` varchar(20) NOT NULL,
`date_birth` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`postal_code` varchar(255) NOT NULL,
`place` varchar(255) NOT NULL,
`school_name` varchar(255) NOT NULL, 
`email` varchar(55) NOT NULL,
`tel` varchar(55) NOT NULL,

PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

This is how i insert the data into the DB:

Now i want to insert a new row in the DB which can have only 2 values: "active" or "inactive" for each user. Default on "inactive". That should be inserted automatically for each user after submit. How can i do that?

3
  • This question is a bit too broad, please checkout stackoverflow.com/help/on-topic and show us what you tried so far. Commented Mar 9, 2018 at 18:31
  • 1
    lets hope the user's first name isn't something like bob")';drop table registered_users;// Commented Mar 9, 2018 at 18:43
  • 1
    stackoverflow.com/questions/60174/… Commented Mar 9, 2018 at 18:43

1 Answer 1

1

When you create a table in a mysql db you can specify a default value for attributes. So if you want a boolean "active" / "inactive" flag you might want to try adding an active attribute to your table. See the added last column here:

CREATE TABLE IF NOT EXISTS `registered_users` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`gender` varchar(20) NOT NULL,
`date_birth` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`postal_code` varchar(255) NOT NULL,
`place` varchar(255) NOT NULL,
`school_name` varchar(255) NOT NULL, 
`email` varchar(55) NOT NULL,
`tel` varchar(55) NOT NULL,
`active` BOOLEAN NOT NULL DEFAULT false,

PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Ref.: https://dev.mysql.com/doc/refman/5.7/en/create-table.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.