0

i have file siswa-tambah.php

    <?php
//siswa-tambah.php
//periksa apakah username = kosong dan hak akses = adm
if(empty($_SESSION['username']) OR ($_SESSION['akses']<>'adm')){
    //jika user belum login
    echo "Anda harus login untuk dapat mengakses halaman ini !\n";
    echo "<a href=index.php>Kembali</a>";
} else {
    if(isset($_POST['submit'])){
        //proses simpan
        $nis=$_POST['nis'];
        $nama=$_POST['nama'];
        $tgl_lahir=$_POST['thn'].'-'.$_POST['bln'].'-'.$_POST['tgl'];
        $sex=$_POST['sex'];
        $pass=$_POST['pass'];
        $uploaddir = 'foto/';
        $foto = basename($_FILES['foto']['name']);

        //sql simpan, password menggunakan nomor induk
        $sql = mysql_query("INSERT INTO siswa VALUES('$nis','$nama','$tgl_lahir','$sex','$pass','$foto')");
        if($sql){
            echo "Data berhasil disimpan!";
        } else {
            echo "Ada ERROR!";
        }
    } else {
?>
<form enctype="multipart/form-data" method="POST" action="">
<table border="0">
<tr>
<td>NIS/USERNAME</td>
<td><input type="text" size="10" name="nis"></td>
</tr>
<tr>
<td>Nama Lengkap</td>
<td><input type="text" size="25" name="nama"></td>
</tr>
<tr>
<td>Tanggal Lahir</td>
<td>
<?php
    echo '<select name="tgl">';
    for($tgl=1; $tgl<=31; $tgl++){
        echo '<option value="'.$tgl.'">'.$tgl.'</option>';
}
        echo '</select>'; 

    echo '<select name="bln">';
    $arrBulan = array(1=>'Januari','Pebruari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','Nopember','Desember');
    foreach($arrBulan as $b => $bln){
        echo '<option value="'.$b.'">'.$bln.'</option>';
    }
        echo '</select>';

        echo '<select name="thn">';
    foreach(range(date('Y'), 1930) as $thn){
        echo '<option value="'.$thn.'">'.$thn.'</option>';
    }
        echo '</select>';
?>
</td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td>
<input type="radio" name="sex" value="L">Laki-Laki 
<input type="radio" name="sex" value="P">Perempuan
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input type="password" name="pass">
<input type="hidden" name="nis" value="<?php echo $hsl['nis']; ?>">
</td>
</tr>
<tr>
<td>Foto</td>
<td><input type="file" name="foto"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Simpan"></td>
</tr>
</table>
</form>
<?php
    }
}
?>

heres my problem when i click Submit button, nis is wrong but others correct , where i can fix this, "nis" when i insert/add "br /> b>Noti" , i'm so confuse please correct my code

Please help, thanks

2
  • Screenshot "nis" is wrong Commented Dec 5, 2013 at 14:16
  • There's a PHP error in there. You need to figure out what it is as that will solve your problem. Commented Dec 5, 2013 at 14:17

1 Answer 1

0

I think the problem is that you have two form objects with the name 'nis':

<td>NIS/USERNAME</td>
<td><input type="text" size="10" name="nis"></td>

and

<input type="hidden" name="nis" value="<?php echo $hsl['nis']; ?>">
1
  • oh yes, you're right now my code work, thank you :) so much Thomas Commented Dec 5, 2013 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.