· 7 years ago · Nov 29, 2018, 01:32 AM
1// TABLE Drug
2DROP TABLE IF EXISTS `Drug`;
3CREATE TABLE IF NOT EXISTS `Drug` (
4`id` int(11) NOT NULL AUTO_INCREMENT,
5`brId` text NOT NULL,
6`nameDrug` text NOT NULL,
7 PRIMARY KEY (`id`)
8 )
9
10// TABLE brand
11 DROP TABLE IF EXISTS `brand`;
12 CREATE TABLE IF NOT EXISTS `brand` (
13 `idBrand` int(11) NOT NULL AUTO_INCREMENT,
14 `brandName` text NOT NULL,
15 `theUse` text NOT NULL,
16 PRIMARY KEY (`idBrand`)
17 )
18
19<?php
20 require_once('include/config.php');
21
22 $id = $_POST['id'];
23
24 $brandName = $_POST['brandName'];
25
26 $theUse = $_POST['theUse'];
27
28 $query = "INSERT INTO brand
29 (brandName,theUse)VALUES('".$brandName."','".$theUse."');";
30
31 $insertBrand = mysqli_query($con,$query);
32 if($insertBrand)
33 {
34 $updatDrug = "UPDATE `drug` SET `brId` = new.idBrand WHERE `id` = '".$id."' ;";
35 $resultEnd = mysqli_query($con,$updatDrug);
36 if($resultEnd){
37 $result = 'OK';
38 echo json_encode($result);
39 }else{
40 $resultno = 'NO';
41 echo json_encode($resultno);
42 }
43 }
44
45mysqli_close($con);
46?>