SHARE
TWEET

list

a guest Apr 26th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3. include 'config.php';
  4. include 'template.html';
  5. if(!isset($_SESSION['username'])){
  6.     header('location:login.php');
  7. }
  8. $name=$_SESSION['username'];
  9. $sqlId="SELECT id FROM users WHERE username='$name'";
  10. $executeId=mysqli_query($con,$sqlId);
  11. while ($row=mysqli_fetch_row($executeId)){
  12.     $id=$row[0];
  13. }
  14. if(isset($_POST['save'])) {
  15.     $nameList = $_POST['listName'];
  16.     $typeList = $_POST['listType'];
  17.     $date = date("Y-m-d h:i:sa");
  18.     $nameListSec = mysqli_real_escape_string($con, $nameList);
  19.     $typeListSec = mysqli_real_escape_string($con, $typeList);
  20.     $addList = "INSERT INTO liste(name, type, date, id) VALUES ('$nameListSec','$typeListSec','$date','$id')";
  21.     $resultat = mysqli_query($con, $addList)
  22.     or die(mysqli_error($con));
  23.     $res = mysqli_affected_rows($con);
  24.  
  25.     if ($res == 1) {
  26.         $selectListId = "SELECT * FROM liste where date='$date' AND id='$id'";
  27.         $resultList = mysqli_query($con, $selectListId);
  28.         while ($ligne = mysqli_fetch_array($resultList)) {
  29.             $listId = $ligne[0];
  30.         }
  31.         if (isset($_POST['insert'])) {
  32.             $nameItem = $_POST['itemName'];
  33.             $prix = $_POST['prix'];
  34.             $quantity = $_POST['quantity'];
  35.             $nameItemSec = mysqli_real_escape_string($con, $nameItem);
  36.             $prixSec = mysqli_real_escape_string($con, $prix);
  37.             $quantitySec = mysqli_real_escape_string($con, $quantity);
  38.             $priceInt = intval($prixSec);
  39.             $quantityInt = intval($quantitySec);
  40.             $price = $prixSec * $quantitySec;
  41.  
  42.  
  43.             $addItem = "INSERT INTO item (name,prixUnitaire,quantite,prixTotal,listId,image) VALUES ('$nameItemSec','$priceInt','$quantitySec','$price','$listId',1)";
  44.             mysqli_query($con, $addItem)
  45.             or die(mysqli_error($con));
  46.         }
  47.  
  48.  
  49.     }
  50.  
  51. }
  52.  
  53.         ?>
  54.         <html>
  55.         <body>
  56.         <div class="form-box">
  57.             <div align="center">
  58.                 <h3>Your List</h3>
  59.             </div>
  60.             <form action="index.php" method="post">
  61.                 List Name:<input type="text" align="left" name="listName"><br>
  62.                 Type List:<input type="text" align="left" name="listType"><br>
  63.                 <input type="submit" name="save" value="Save">
  64.                 <br>
  65.                 Item Name: <input type="text" align="left" name="itemName"><br>
  66.                 Prix :<input type="number" align="left" name="prix">
  67.                 Quantity: <input type="number" align="left" name="quantity"><br>
  68.                 <input type="submit" name="insert" value="Insert">
  69.             </form>
  70.  
  71.  
  72.         </body>
  73.         </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top