How to automatically subtract or add data from columns in mysql
I am building a system for doctors and patients where the patients submit the type of the medical examination and the quantity of medicine they use. I want to be able to subtract the value of the quantity in the database with PHP but without the user input. The type of the examination and the quantity are on different tables. Is that possible?
What I have done so far :
$records = $handler->query("INSERT INTO exam(id, code, name, medical_exam) VALUES('', '$_POST[code]', '$_POST[name]', '$_POST[medical_exam]')");
And I want to also do this:
$records = $handler->query("UPDATE quantity AND SET quantity = quantity -10");
is that possible within 1 MySQL statement??
is that possible within 1 mysql statement??
Yes. Just seperate your SQL Statements with semicolon
Do something like
$records = $handler->query("INSERT INTO `exam`(`id`, `code`, `name`, `medical_exam`) VALUES('', '$_POST[code]', '$_POST[name]', '$_POST[medical_exam]');UPDATE `quantity` AND SET `quantity` = (`quantity` - 10);");
- A Linux, Apache, MySQL, PHP (LAMP) stack is a combination of open source software that is typically installed together to enable a server to host dynamic […]
- MySQL is an the most popular open-source database management system, in most of hosting company its has been bundle by LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. Another alternative […]
- MySQL is the world’s most popular open-source database. Despite its powerful features, MySQL is simple to set up and easy to use. Below are some instructions […]