add.php - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of add.php.php

  1.  
  2. <html>
  3.   
  4. <head>
  5.     <meta http-equiv="Content-Type" 
  6.         content="text/html; charset=UTF-8">
  7.   
  8.     <title>Add List</title>
  9.   
  10.     <link rel="stylesheet" href=
  11. "https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  12.     <link rel="stylesheet" href="css/style.css">
  13. </head>
  14.   
  15. <body>
  16.     <div class="container mt-5">
  17.         <h1>Add Grocery List</h1>
  18.         <form action="add.php" method="POST">
  19.             <div class="form-group">
  20.                 <label>Item name</label>
  21.                 <input type="text" 
  22.                     class="form-control" 
  23.                     placeholder="Item name" 
  24.                     name="iname" />
  25.             </div>
  26.   
  27.             <div class="form-group">
  28.                 <label>Item quantity</label>
  29.                 <input type="text" 
  30.                     class="form-control" 
  31.                     placeholder="Item quantity" 
  32.                     name="iqty" />
  33.             </div>
  34.   
  35.             <div class="form-group">
  36.                 <label>Item status</label>
  37.                 <select class="form-control" 
  38.                     name="istatus">
  39.                     <option value="0">
  40.                         PENDING
  41.                     </option>
  42.                     <option value="1">
  43.                         BOUGHT
  44.                     </option>
  45.                     <option value="2">
  46.                         NOT AVAILABLE
  47.                     </option>
  48.                 </select>
  49.             </div>
  50.             <div class="form-group">
  51.                 <label>Date</label>
  52.                 <input type="date" 
  53.                     class="form-control" 
  54.                     placeholder="Date" 
  55.                     name="idate">
  56.             </div>
  57.             <div class="form-group">
  58.                 <input type="submit" 
  59.                     value="Add" 
  60.                     class="btn btn-danger" 
  61.                     name="btn">
  62.             </div>
  63.         </form>
  64.     </div>
  65.   
  66.     <?php
  67.         if(isset($_POST["btn"])) {
  68.             include("connect.php");
  69.             $item_name=$_POST['iname'];
  70.             $item_qty=$_POST['iqty'];
  71.             $item_status=$_POST['istatus'];
  72.             $date=$_POST['idate'];
  73.       
  74.   
  75.             $q="insert into grocerytb(Item_name,
  76.             Item_Quantity,Item_status,Date)
  77.             values('$item_name',$item_qty,
  78.             '$item_status','$date')";
  79.   
  80.             mysqli_query($con,$q);
  81.             header("location:index.php");
  82.         }
  83.           
  84.         // if(!mysqli_query($con,$q))
  85.         // {
  86.             // echo "Value Not Inserted";
  87.         // }
  88.         // else
  89.         // {
  90.             // echo "Value Inserted";
  91.         // }
  92.     ?>
  93. </body>
  94.   
  95. </html>
  96.  
File Description
  • add.php
  • PHP Code
  • 23 Sep-2022
  • 2.61 Kb
You can Share it: