I have a form where the user can input a name for an instructor
and/or faculty
person. Based on the fields submitted I want to store values into the person
table. If both an instructor and faculty values are submitted I would like to create a different row for each and be able to identify their role instructor
or faculty
. I in the table I have bit flags to help determine the role
. But how can I store the bit value in the table to identify if it’s either instructor
or `faculty?
<?php
if(isset($_POST['submit'])){
$bitmask = 1|2;
$db_con = new mysqli(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
$db_insert = $db_con->prepare("INSERT INTO person (`person_name`,`instructor_role`)
VALUES (?,?)");
$db_insert->bind_param('s', $_POST['instructor_name'], $bitmask);
$db_insert->execute();
} ?>
<form action="index.php" method="POST">
Instructor Name:<input type="text" name="instructor_name">
Faculty Name:<input type="text" name="contact_name">
<input value="SAVE" name="submit" type="submit">
</form>
Table
CREATE TABLE IF NOT EXISTS `person` (
`person_id` int(11) NOT NULL auto_increment,
`contact_role` bit(8) NOT NULL,
`instructor_role` bit(8) NOT NULL,
`person_name` varchar(50) NOT NULL,
PRIMARY KEY (`person_id`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
this is what you want:
$bit =1;
$bit2 = 2;
$bit3= 4;
$bit4= 8;
//1+2+8=11
$result = $bit | $bit2 |$bit4;
//this is still 11
$result = $result | $bit;
if you need the SQL part please tell, will update
depends how you define instructor value and faculty
i will assume instructor is 1 and faculty is 2
not sure if bit is i or something else so please check it
$db_insert = $db_con->prepare("INSERT INTO person (`person_name`,`instructor_role`)
VALUES (?,?)");
$db_insert->bind_param('s', $_POST['instructor_name'] || $_POST['faculty_name']);
$db_insert->bind_param('i',1|2);
$db_insert->execute();