Guest User

php help

a guest
Aug 26th, 2023
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.80 KB | Source Code | 0 0
  1. add supplier
  2. <?php
  3. require_once '../bootstrap.php';
  4. LogInCheck();
  5. //only POST request is accepted
  6. if($_SERVER['REQUEST_METHOD'] == 'POST') {
  7.  
  8. // Sanitize POST array
  9. $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
  10. //print_r($_POST);
  11.  
  12.  
  13. //trim the values
  14. $supplier_name = trim($_POST['supplier_name']);
  15. $supplier_details = trim($_POST['supplier_details']);
  16. $Tel = trim($_POST['Tel']);
  17. $Email = trim($_POST['Email']);
  18. $Poids_moyen = trim($_POST['Poids_moyen']);
  19. $Dimontion = trim($_POST['Dimontion']);
  20.  
  21.  
  22. //connect to db
  23. require_once '../db.php';
  24. $sql = "INSERT INTO `supplier` (`supplier_name`, `supplier_details`, `Tel`, `Email`, `Poids_moyen`, `Dimontion`, `added_at`) VALUES ('$supplier_name', '$supplier_details', '$Tel', '$Email', '$Poids_moyen', '$Dimontion', CURDATE())";
  25. $query = $conn->query($sql);
  26. //var_dump($query);
  27. //var_dump($sql);
  28.  
  29. if($query == true)
  30. {
  31. $_SESSION['success'] = 'supplier added successfully';
  32. //redirect to item home
  33. header('location: ../suppliers.php');
  34. }
  35. else
  36. {
  37. $_SESSION['error'] = 'Something went wrong while adding supplier department';
  38. //redirect to item home
  39. header('location: ../suppliers.php');
  40. }
  41.  
  42. }
  43. else
  44. {
  45. $_SESSION['error'] = 'Something went wrong while adding supplier';
  46. header('location: ../suppliers.php');
  47. }
  48. add supllier model
  49. <!-- Add New -->
  50. <div class="modal fade" id="addnew" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  51. <div class="modal-dialog">
  52. <div class="modal-content">
  53. <div class="modal-header">
  54. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  55. <center><h4 class="modal-title" id="myModalLabel">Ajouter une Boutique</h4></center>
  56. </div>
  57. <div class="modal-body">
  58. <div class="container-fluid">
  59. <form method="POST" action="./actions/__add_supplierModel.php">
  60. <div class="row form-group">
  61. <div class="col-sm-2">
  62. <label class="control-label modal-label">Boutique: </label>
  63. </div>
  64. <div class="col-sm-10">
  65. <input type="text" class="form-control" maxlength="20" name="supplier_name" placeholder="enter supplier name" required>
  66. </div>
  67. </div>
  68. <div class="row form-group">
  69. <div class="col-sm-2">
  70. <label class="control-label modal-label">Nature:</label>
  71. </div>
  72. <div class="col-sm-10">
  73. <input type="text" class="form-control" maxlength="50" name="supplier_details" placeholder="supplier details" required>
  74. </div>
  75. <div class="row form-group">
  76. <div class="col-sm-2">
  77. <label class="control-label modal-label">TEl:</label>
  78. </div>
  79. <div class="col-sm-10">
  80. <input type="text" class="form-control" maxlength="50" name="Tel" placeholder="Tel" required>
  81. </div>
  82. <div class="row form-group">
  83. <div class="col-sm-2">
  84. <label class="control-label modal-label">Email:</label>
  85. </div>
  86. <div class="col-sm-10">
  87. <input type="text" class="form-control" maxlength="50" name="Email" placeholder="Email" required>
  88. </div>
  89. <div class="row form-group">
  90. <div class="col-sm-2">
  91. <label class="control-label modal-label">Poids Moyen:</label>
  92. </div>
  93. <div class="col-sm-10">
  94. <input type="text" class="form-control" maxlength="50" name="Poids_moyen" placeholder="Poids_moyen" required>
  95. </div>
  96. <div class="row form-group">
  97. <div class="col-sm-2">
  98. <label class="control-label modal-label">Dimontions:</label>
  99. </div>
  100. <div class="col-sm-10">
  101. <input type="text" class="form-control" maxlength="50" name="Dimontion" placeholder="Dimontion" required>
  102. </div>
  103. </div>
  104.  
  105. </div>
  106. <div class="modal-footer">
  107. <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
  108. <button type="submit" name="add" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> Save</a>
  109. </form>
  110. </div>
  111.  
  112. </div>
  113. </div>
  114. </div>
  115. database
  116. -- phpMyAdmin SQL Dump
  117. -- version 4.6.5.2
  118. -- https://www.phpmyadmin.net/
  119. --
  120. -- Host: 127.0.0.1
  121. -- Generation Time: Aug 01, 2021 at 07:19 AM
  122. -- Server version: 5.6.21
  123. -- PHP Version: 5.6.3
  124.  
  125. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  126. SET time_zone = "+00:00";
  127.  
  128.  
  129. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  130. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  131. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  132. /*!40101 SET NAMES utf8mb4 */;
  133.  
  134. --
  135. -- Database: `stockphp`
  136. --
  137.  
  138. -- --------------------------------------------------------
  139.  
  140. --
  141. -- Table structure for table `department`
  142. --
  143.  
  144. CREATE TABLE `department` (
  145. `dept_id` int(11) NOT NULL,
  146. `dept_name` varchar(30) NOT NULL,
  147. `password` varchar(255) NOT NULL,
  148. `role` int(11) NOT NULL DEFAULT '0',
  149. `dept_details` varchar(255) NOT NULL,
  150. `added_at` date DEFAULT NULL
  151. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  152.  
  153. --
  154. -- Dumping data for table `department`
  155. --
  156.  
  157. INSERT INTO `department` (`dept_id`, `dept_name`, `password`, `role`, `dept_details`, `added_at`) VALUES
  158. (1, 'Stock Administrator', '12345', 1, 'default stock department', '2018-03-27'),
  159. (2, 'Department 2', '3875', 0, 'Dept 2', '2018-04-05'),
  160. (10, 'Department 3', '12345', 0, 'Dept 3', '2018-04-04'),
  161. (16, 'Department 4', '12345', 0, 'Dept 4', '2018-04-19');
  162.  
  163. -- --------------------------------------------------------
  164.  
  165. --
  166. -- Table structure for table `item`
  167. --
  168.  
  169. CREATE TABLE `item` (
  170. `item_id` int(11) NOT NULL,
  171. `item_name` varchar(30) NOT NULL,
  172. `item_cat` varchar(30) NOT NULL,
  173. `item_detail` varchar(255) NOT NULL,
  174. `bill_no` varchar(30) DEFAULT NULL,
  175. `supplier_id` int(11) NOT NULL,
  176. `dept_id` int(11) NOT NULL DEFAULT '1',
  177. `supplied_at` date NOT NULL
  178. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  179.  
  180. --
  181. -- Dumping data for table `item`
  182. --
  183.  
  184. INSERT INTO `item` (`item_id`, `item_name`, `item_cat`, `item_detail`, `bill_no`, `supplier_id`, `dept_id`, `supplied_at`) VALUES
  185. (465, 'Item One', ' First Category', 'Demo Details 12345', '100', 3, 2, '2021-07-29'),
  186. (466, 'Item Two', ' Second Category', 'Demo Details Demo', '101', 1, 1, '2021-07-29'),
  187. (467, 'Item Three', ' Third Category', 'Demo Item Details', '103', 9, 1, '2021-08-01'),
  188. (468, 'Item Four', ' Fourth Category', 'Demo Details', '104', 3, 1, '2021-08-01'),
  189. (469, 'Item Five', ' Second Category', 'Demo Demo Demo', '105', 2, 1, '2021-08-01'),
  190. (470, 'Item Six', ' Third Category', 'Demo Demo', '106', 2, 1, '2021-08-01'),
  191. (471, 'Item Seven', ' First Category', 'Demo Demo', '107', 6, 1, '2021-08-01'),
  192. (472, 'Item Eight', ' First Category', 'Demo Details', '108', 7, 1, '2021-08-01'),
  193. (473, 'Item Nine', ' Fourth Category', 'Demo Details N', '109', 3, 1, '2021-08-01'),
  194. (474, 'Item Ten', ' Fifth Category', 'This is a demo detail', '110', 5, 1, '2021-08-01'),
  195. (475, 'Item Eleven', ' Fourth Category', 'Demo Details..', '111', 4, 1, '2021-08-01'),
  196. (476, 'Item Twelve', ' Fifth Category', 'Demo Cntn', '112', 6, 1, '2021-08-01');
  197.  
  198. -- --------------------------------------------------------
  199.  
  200. --
  201. -- Table structure for table `supplier`
  202. --
  203.  
  204. CREATE TABLE `supplier` (
  205. `supplier_id` int(11) NOT NULL,
  206. `supplier_name` varchar(30) NOT NULL,
  207. `supplier_details` varchar(255) NOT NULL,
  208. `Tel` int(255) NOT NULL,
  209. `Email` varchar(255) NOT NULL,
  210. `supplier_details` varchar(255) NOT NULL,
  211. `Poids_moyen` varchar(255) NOT NULL,
  212. `Dimontion` int(255) NOT NULL,
  213. `supplier_name` varchar(30) NOT NULL,
  214. `added_at` date NOT NULL
  215. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  216.  
  217. --
  218. -- Dumping data for table `supplier`
  219. --
  220.  
  221. INSERT INTO `supplier` (`supplier_id`, `supplier_name`, `supplier_details`, `Tel`, `Email`, `Poids_moyen`, `Dimontion`, `added_at`) VALUES
  222. (1, 'Fozzby', '984 Woodstock Drive', '2019-04-12'),
  223. (2, 'Redsupplies', '4407 Jerry Toth Drive', '2019-02-01'),
  224. (3, 'MegaGoods Supplies', '1908 Leo Street', '2020-01-17'),
  225. (4, 'Mooszer Electronics', '1491 Shinn Avenue', '2019-12-06'),
  226. (5, 'AEC Components', '1743 Washburn Street', '2019-12-13'),
  227. (6, 'MG Foods', '2617 Happy Hollow Road', '2019-10-18'),
  228. (7, 'Vista Suppliers', '2820 Sunset Drive', '2019-02-07'),
  229. (8, 'Edens Collection', '4407 Jerry Toth Drive', '2019-03-01'),
  230. (9, 'USPharma', '2781 Leverton Cove Road', '2019-05-04');
  231.  
  232. --
  233. -- Indexes for dumped tables
  234. --
  235.  
  236. --
  237. -- Indexes for table `department`
  238. --
  239. ALTER TABLE `department`
  240. ADD PRIMARY KEY (`dept_id`),
  241. ADD UNIQUE KEY `dept_name` (`dept_name`),
  242. ADD KEY `dept_name_2` (`dept_name`);
  243.  
  244. --
  245. -- Indexes for table `item`
  246. --
  247. ALTER TABLE `item`
  248. ADD PRIMARY KEY (`item_id`),
  249. ADD KEY `item_cat` (`item_cat`),
  250. ADD KEY `supplier_id` (`supplier_id`),
  251. ADD KEY `dept_id` (`dept_id`),
  252. ADD KEY `supplier_id_2` (`supplier_id`);
  253.  
  254. --
  255. -- Indexes for table `supplier`
  256. --
  257. ALTER TABLE `supplier`
  258. ADD PRIMARY KEY (`supplier_id`),
  259. ADD UNIQUE KEY `supplier_name` (`supplier_name`);
  260. ADD KEY `supplier_details` (`supplier_details`),
  261. ADD KEY `Tel` (`Tel`),
  262. ADD KEY `Email` (`Email`),
  263. ADD KEY `Poids_moyen` (`Poids_moyen`),
  264. ADD KEY `Dimontion` (`Dimontion`),
  265.  
  266. --
  267. -- AUTO_INCREMENT for dumped tables
  268. --
  269.  
  270. --
  271. -- AUTO_INCREMENT for table `department`
  272. --
  273. ALTER TABLE `department`
  274. MODIFY `dept_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;
  275. --
  276. -- AUTO_INCREMENT for table `item`
  277. --
  278. ALTER TABLE `item`
  279. MODIFY `item_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=477;
  280. --
  281. -- AUTO_INCREMENT for table `supplier`
  282. --
  283. ALTER TABLE `supplier`
  284. MODIFY `supplier_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
  285. --
  286. -- Constraints for dumped tables
  287. --
  288.  
  289. --
  290. -- Constraints for table `item`
  291. --
  292. ALTER TABLE `item`
  293. ADD CONSTRAINT `item_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `supplier` (`supplier_id`) ON UPDATE CASCADE,
  294. ADD CONSTRAINT `item_ibfk_2` FOREIGN KEY (`dept_id`) REFERENCES `department` (`dept_id`) ON UPDATE CASCADE;
  295.  
  296. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  297. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  298. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  299. supplier php
  300. <?php
  301. require_once 'includes/header.php';
  302. LogInCheck();
  303. require_once 'includes/admin_nav.php';
  304. ?>
  305. <!--exp1-->
  306.  
  307. <div class="col-sm-10 col-sm-offset-1">
  308. <div class="row">
  309. <!--place for error message flashing-->
  310. <?php
  311. //this will display any kind of error message as
  312. flash();
  313. ?>
  314. </div>
  315. <div class="row">
  316. <a href="#addnew" data-toggle="modal" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> New</a>
  317. <a href="./reports/all_suppliers.php" target="_new" class="btn btn-success pull-right"><span class="glyphicon glyphicon-print"></span> PDF</a>
  318. </div>
  319. <div class="" style="height: 10px;">
  320. </div>
  321. <div class="row">
  322. <table id="myTable" class="table table-hover table-bordered table-striped table-responsive">
  323. <thead>
  324. <th>#</th>
  325. <th>nom de Boutique</th>
  326. <th>Nature collis</th>
  327. <th>Tel</th>
  328. <th>Email</th>
  329. <th>Poids Moyen</th>
  330. <th>Dimontion</th>
  331. <th>ADDED AT</th>
  332. <th>ACTION</th>
  333. </thead>
  334. <tbody>
  335. <?php
  336. include_once('db.php');
  337. $sql = "SELECT * FROM `supplier`";
  338.  
  339.  
  340. $query = $conn->query($sql);
  341.  
  342. $i=1;
  343. while($row = $query->fetch_assoc())
  344. {
  345. echo"<tr>
  346. <td>".$i."</td>
  347. <td>".$row['supplier_name']."</td>
  348. <td>".$row['supplier_details']."</td>
  349. <td>".$row['Tel']."</td>
  350. <td>".$row['Email']."</td>
  351. <td>".$row['Poids_Moyen']."</td>
  352. <td>".$row['Dimontion']."</td>
  353. <td>".$row['added_at']."</td>
  354. <td><a href='#edit_".$row['supplier_id']."' class='btn btn-success btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-edit'></span> Edit</a>
  355. </tr>";
  356. $i++;
  357. include('models/edit_delete_supplierModel.php') ;
  358. }
  359. ?>
  360. </tbody>
  361. </table>
  362. <hr>
  363. <?php
  364. //add required models
  365. require_once 'models/add_supplierModel.php';
  366. ?>
  367. </div>
  368. </div>
  369. </div>
  370.  
  371. <!--end exp1-->
  372. <?php require_once './includes/footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment