add.php

 avatar
Sndivrgwn26
php
a year ago
636 B
18
Indexable
Never
<?php

$config = mysqli_connect('localhost', 'root', '', 'eskul');

if ((!$config)) {
    # code...
    echo "error";
    die();
}

$input = $_POST;
$nama = $input['nama'];
$kelas = $input['kelas'];
$jurusan = $input['jurusan'];
$nis = $input['nis'];
$no = $input['no'] ?? 0;

if ($no !== 0) {
    $query = "UPDATE anggota set nama='$nama',kelas='$kelas',jurusan='$jurusan',nis='$nis' WHERE no='$no'";
} else {
    $query = "INSERT INTO anggota (nama,kelas,jurusan,nis) VALUES ('$nama','$kelas','$jurusan','$nis')";
}

$result = mysqli_query($config, $query);
if ($result) {
    header('location:index.php');
}