Hello,
I have a code like below.
If the data from the form is not saved in the database, save it to the database.
If the data from the form is saved in the database, continue.
No problem so far
My question is:
The data is saved but there is new data for someone in the empty column how do I update this empty column?
CREATE TABLE IF NOT EXISTS `table` (
`id` int NOT NULL AUTO_INCREMENT,
`company_email` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`company_name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`company_authorized` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`company_mobile_phone` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`company_phone` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`company_address` varchar(250) NOT NULL,
`group` int NOT NULL,
`userid` int NOT NULL,
`created` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `company_email` (`company_email`),
UNIQUE KEY `company_name` (`company_name`),
UNIQUE KEY `company_mobile_phone` (`company_mobile_phone`),
UNIQUE KEY `company_phone` (`company_phone`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3;
$company_email = filter_input(INPUT_POST,'company_email');
$company_name = filter_input(INPUT_POST,'company_name');
$company_authorized = filter_input(INPUT_POST,'company_authorized');
$company_mobile_phone = filter_input(INPUT_POST,'company_mobile_phone');
$company_phone = filter_input(INPUT_POST,'company_phone');
$company_address = filter_input(INPUT_POST,'company_address');
$company = $db->prepare(" SELECT * FROM table WHERE company_email=? AND company_name=? AND company_authorized=? AND company_mobile_phone=? AND company_phone=? ");
$company->execute([$company_email,$company_name,$company_authorized,$company_mobile_phone,$company_phone]);
if($company->rowCount() == '0'){
$sql = $PDOdb->prepare("INSERT INTO table (
company_email,
company_name,
company_authorized,
company_mobile_phone,
company_phone,
company_address,
group,
userid,
created)
VALUES (
:company_email,
:company_name,
:company_authorized,
:company_mobile_phone,
:company_phone,
:company_address,
:group
:userid,
:created)");
$sql->bindValue(':company_email', !empty($company_email) ? $company_email : null, PDO::PARAM_STR);
$sql->bindValue(':company_name', !empty($company_name) ? $company_name : null, PDO::PARAM_STR);
$sql->bindValue(':company_authorized', !empty($company_authorized) ? $company_authorized : null, PDO::PARAM_STR);
$sql->bindValue(':company_mobile_phone', !empty($company_mobile_phone) ? $company_mobile_phone : null, PDO::PARAM_STR);
$sql->bindValue(':company_phone', !empty($company_phone) ? $company_phone : null, PDO::PARAM_STR);
$sql->bindValue(':company_address', !empty($company_address) ? $company_address : null, PDO::PARAM_STR);
$sql->bindValue(':group', isset($_SESSION['group']) && !empty($_SESSION['group']) ? $_SESSION['group'] : 0, PDO::PARAM_INT);
$sql->bindValue(':userid', isset($_SESSION['userid']) && !empty($_SESSION['userid']) ? $_SESSION['userid'] : 0, PDO::PARAM_INT);
$sql->bindValue(':created', time(), PDO::PARAM_INT);
$sql->execute();