Advertisement
abpnug

Untitled

Oct 20th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <?php
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $db = "belajar";
  8.  
  9. $conn = new mysqli($servername,$username,$password,$db);
  10.  
  11. if ($conn->connect_error){
  12.     die ("Connection failed:" .$conn->connect_error);
  13. }
  14.  
  15. $sql = "SELECT nama_produk, harga FROM produk";
  16.  
  17. $result = $conn->query($sql);
  18. ?>
  19. <head>
  20.     <title>Transaksi</title>
  21.     <h1>Transaksi</h1>
  22. </head>
  23. <p>Nama Produk</p>
  24. <?php
  25. $id=0;
  26. if ($result->num_rows > 0){
  27.     while($data = $result->fetch_assoc()){
  28.         $id++;
  29.   echo    "<input type='radio' name='item' value='{$data['harga']}' id='id$id'>".$data['nama_produk']."</br>";
  30.  
  31.  
  32.      
  33.     }
  34. } else{
  35.     echo "0 results";
  36. }
  37. $query = "SELECT harga from produk WHERE nama_produk = 'value'"
  38. ?>
  39.  
  40. <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  41. <script>
  42.     $(document).ready(function(){
  43.         $("input[type='radio']").click(function(){
  44.             var radioValue = $("input[name='item']:checked").val();
  45.             if(radioValue){
  46.                 // alert("Your are a - " + radioValue);
  47.                 $('#nilai').val(radioValue);
  48.             }
  49.         });
  50.     });
  51.  
  52. </script>
  53.  
  54.    
  55. <form action="transaksi.php">
  56.     Harga: <input type="text" id="nilai" name="nilai">
  57.     Kuantitas: <input type="text" id="qty" name="qty">
  58.     <script>
  59.     $(document).ready(function(){
  60.         $("input[type='text']").click(function(){
  61.             var radioValue = $("input[name='qty']:checked").val();
  62.             if(radioValue){
  63.                 // alert("Your are a - " + radioValue);
  64.                 $('#qty').val(radioValue);
  65.             }
  66.         });
  67.     });
  68.  
  69. </script>
  70. </form>
  71.  
  72. <?php
  73.  
  74. $conn->close();
  75.  
  76. ?>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement