dougan1465
dougan1465
2017-01-21 12:36

无法显示注册表单错误。 输入也无法插入到mysql中

Sorry. There's another malay language in my code..Hope u understand by looking at the code only..The problem is, if i enter any error input, the error is not display. And if there is no any error,it won't inserted in mysql. Thanks...

<?php
include ("connection.php");

$namaErr = $noicErr = $katalaluanErr = "";

if (isset($_POST['btnSubmit'])) {
    include ("connection.php");

    if (empty($_POST[$nama])) {
        $namaErr = "Anda wajib mengisi nama anda di ruangan ini!";
    }else if(strlen($nama) < 3) {
        $error = true;
        $namaErr= "Nama hendaklah tidak kurang daripada 3 karakter";
    } else if (!preg_match("/^[a-zA-Z ]+$/",$nama)) {
        $error = true;
        $namaErr= "Nama mestilah mengandungi huruf dan ruang sahaja";
    }

    //ic
    if (empty($_POST[$noic])) {
        $noicErr = "Anda wajib mengisi nombor IC anda di ruangan ini!";
    }else if (strlen($noic) != 12) {
        $error = true;
        $noicErr = "Nombor IC hendaklah tidak kurang daripada 12 nombor    
        digit";
    } else if (!is_numeric($noic)) {
        $error = true;
        $noicErr = "Nombor IC mestilah mengandungi nombor sahaja";
    } 

    //katalaluan
    if (empty($_POST[$katalaluan]))  {
        $katalaluanErr = "Anda wajib mengisi kata laluan anda di    
        ruangan ini!";
    } else if(strlen($katalaluan) < 8) {
        $error = true;
        $katalaluanErr = "Kata laluan hendaklah tidak kurang daripada 8";
    } 
}
if (!$error){ 
    $EncryptPassword = md5($katalaluan);

    $query="INSERT INTO daftar_pengguna(nama, noic, katalaluan)  
            VALUES('$nama','$noic', '$EncrpytPassword')";
    $res = mysql_query($query);
}
?>

And below is the form.

<form name="form1" method="post" action="borangdaftar.php">

    <table width="544" border="1">
    <tr>
         <th scope="row"><span class="style32">Nama</span></th>
         <td><input name="nama" type="text" size="30" maxlength="50" value=" 
<?php echo htmlspecialchars($nama); ?>">*<span class="isa_error"><? 
         php echo $nama; ?></span></td>
</tr>
<tr>
    <th width="208" scope="col"><span class="style32">No IC </span> </th>
    <td width="320"><input name="noic" type="text" size="12"       
         maxlength="50" value="<?php echo htmlspecialchars($noic); ?>">* 
         <span class="isa_error"><?php echo $noic; ?></span>
    </td>
</tr>
<tr>
    <th scope="row"><span class="style32">Kata Laluan</span></th>
    <td><input name="katalaluan" type="password" size="30"  
         maxlength="50" value="<?php echo htmlspecialchars($katalaluan); ?  
         >">*<span class="isa_error"><?php echo $katalaluan; ?></span>
    </td>
</tr>
</table>
<p align="center">
    <input name="btnSubmit" type="submit" value="Hantar">
    <input name="btnReset" type="reset" Value="reset"> </p>

</form>
</th></tr></table>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doulang1945 doulang1945 4年前

    my problem solved.1. i deleted the 'if .... ' above the $encrypted. 2. change to '$namaErr and so on...' in the beside the span error and declare the variable as '$nama= $_POST['nama']; and so on....'. Thanks for your support... :) time to add more features in my system. hope goes well...

    点赞 评论 复制链接分享