gpt4 book ai didi

PHP/MySQL/HTML 添加用户错误?

转载 作者:行者123 更新时间:2023-11-30 00:57:51 25 4
gpt4 key购买 nike

我有文件 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
}
}
?>

这是我点击提交按钮时的问题,nis 是错误的,但其他人是正确的,我可以在哪里解决这个问题,当我插入/添加“br/> b>Noti”时“nis”,我很困惑,请更正我的代码

请帮忙,谢谢

最佳答案

我认为问题在于您有两个名为“nis”的表单对象:

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

<input type="hidden" name="nis" value="<?php echo $hsl['nis']; ?>">

关于PHP/MySQL/HTML 添加用户错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20402112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com