-2

Soo, i have a form that i use to send data to mysql but when i click submit the form didnt send anything to mysql but there is no error shown either. I also try var_dump($_POST) and it show no data. How'd i fix it? thanks.

The code:

  <?php
  include '../koneksi.php';
  $awal_sewa = $_POST['awal_sewa'];
  $akhir_sewa = $_POST['akhir_sewa'];

  $number_days = ((strtotime($akhir_sewa) - strtotime($awal_sewa)) / (60 * 60 * 24));
  $total_price = 0;

  $harga = mysqli_query($koneksi, "select harga from kamar");

  $id = $_GET['id'];
  $data = mysqli_query($koneksi,"select * from kamar where id='$id'");
  while($d = mysqli_fetch_array($data)){

    $total_price = $number_days * $d['harga'];
    ?>

        <form role="form" action="store.php">


                  <input type="hidden" name="id_kamar" class="inside" value="<?php echo $d['id']; ?>">

                  <input type="date" class="form-control" name="konfirmasi_awal_sewa" placeholder="Enter Number" value="<?php echo $awal_sewa; ?>" readonly>

                  <input type="date" class="form-control" name="konfirmasi_akhir_sewa" placeholder="" value="<?php echo $akhir_sewa; ?>" readonly>

                  <input type="text" class="form-control col-sm" name="total_hari" value="<?php echo (int)$number_days;?> hari" readonly>

                  <input type="text" class="form-control col-sm" name="total_harga" value="Rp<?php echo (int)$total_price;?>,-" readonly>
                <?php
              }
              ?>

            <button type="submit" class="btn btn-primary">Sewa</button>
        </form>

Store.php:

<?php var_dump($_POST); ?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Who Know
  • 23
  • 4
  • Add method="POST" in your
    tag.
    – Umair Malik Mar 22 '20 at 18:49
  • Also you are using both $_POST and $_GET, you can't use both for same form. You should use $_POST if form method is post. – Umair Malik Mar 22 '20 at 18:50
  • 2
    You're also wide open to [SQL injection](https://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work). You should use [prepared statements](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead. – El_Vanja Mar 22 '20 at 18:52
  • 1
    @UmairMalik He can use both through **AJAX** but not through `form` – xxMrPHDxx Mar 22 '20 at 18:54

1 Answers1

-1

You need to specify method property for the form. The default method is GET

You need to change the form in the while loop to be

<form method="POST" role="form" action="store.php">
xxMrPHDxx
  • 657
  • 5
  • 11