douyingmou1389 2013-03-15 08:00
浏览 14

简单的PHP程序无法正常工作

The checkbox is not working properly. It has 3 checkbox. when i select all three checkbox i don't get any error. but when i select 1 or 2 checkbox i am getting error like this :

Notice: Undefined index: chke in C:\wamp\www\test\secpage.php on line 16

<html>
<body>
<table>
    <form method="post" action="secpage.php">
        <tr>
            <td colspan="2"><center><h4>Registartion Form</h4></center></td>
        </tr>

        <tr>
            <td>Username : </td>
            <td><input type="text" name="txtname" value=""/></td>
        </tr>

        <tr>
            <td>Password : </td>
            <td><input type="password" name="txtpass" vale=""/></td>
        </tr>

        <tr>
            <td>Email : </td>
            <td><input typ="text" name="txtemail" value=""/></td>
        </tr>

        <tr>
            <td>Address : </td>
            <td><textarea name="add" /></textarea></td>
        </tr> 

        <tr>
            <td>Subjects : </td>
            <td><input type="checkbox" name="chkm" value="Maths"</td>Maths
            <td><input type="checkbox" name="chks" value="Science"</td>Science
            <td><input type="checkbox" name="chke" value="English"</td>English 
        </tr>

        <tr>
            <td>Gender : </td>
            <td><input type="radio" name="gen" value="Male"/>Male
                <input type="radio" name="gen" value="Female"/>Female
             </td>
         </tr>

         <tr>
            <td colspan="2"><center><input type="submit" value="Submit"/></center></td>
         </tr>



</body>
</html>

This is php page :

<html>
<body>
<?php
    $uname=$_POST["txtname"];
    $pass=$_POST["txtpass"];
    $email=$_POST["txtemail"];
    $add=$_POST["add"];
    $subm=$_POST["chkm"];
    $subs=$_POST["chks"];
    $sube=$_POST["chke"];   
    $gen=$_POST["gen"];
?>

<table>
<tr>
    <td>Username : </td>
    <td><?php echo $uname; ?></td>
</tr>

<tr>
    <td>Password : </td>
    <td><?php echo $pass; ?></td>
</tr>

<tr>
    <td>Email : </td>
    <td><?php echo $email; ?></td>
</tr>

<tr>
     <td>Address : </td>
     <td><?php echo $add; ?></td>
</tr>

<tr>
    <td>Subject Selected : </td>
    <td><?php echo $subm." ".$subs." ".$sube; ?></td>
</tr>

<tr>
    <td>Gender : </td>
    <td><?php echo $gen ?></td>
</tr>

</table>
</body>
</html>

Any help will be appreciated.

  • 写回答

5条回答 默认 最新

  • dpsq8476 2013-03-15 08:02
    关注

    A checkbox that isnt checked does not send it's value in the post. So $_POST["chke"] doesn't actually exist. You should check for existence before getting the value from the post.

    if(isset($_POST["chke"]))
      $sube = $_POST["chke"];
    
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害