Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 这段程序总是无法在生成的界面中提交数据,总是提示带星号的信息未填完整,但我确实已经填完整了

这段程序总是无法在生成的界面中提交数据,总是提示带星号的信息未填完整,但我确实已经填完整了

Jun 23, 2016 pm 02:19 PM

本帖最后由 jackbill43 于 2013-08-15 15:09:41 编辑

php

新手求教
nbsp;HTML>



教室添加/修改


    
include_once("base-class.php");

//新建sae数据库类
$mysql = new SaeMysql();

//获取需要修改的教室ID号传入
$class_id=intval($_GET["class_id"]);

//获取操作标识传入
$action=$_POST["action"];
$action= string::un_script_code($action);
$action= string::un_html($action);

//判断是否修改,如果传入了教室ID,进行数据库查询获取全部内容
if($class_id)
{
$class_value=$mysql->getLine("select * from class where class_id=$class_id");
    if(!$class_value)
{
echo "<script>alert('无此教室');history.back();</script>";
exit;
}
}

//如果获取到操作标识,进行录入或者修改操作
if($action=="update")
{
    //获取表单传入数据
$old_class_id=$_POST["class_id"];
$class_name=$_POST["class_name"];
$class_number=$_POST["class_number"];
    $class_fid=$_POST["class_fid"];
    $class_status=$_POST["class_status"];

    //传入数据过滤
    $old_class_id=intval($old_class_id);
    $class_name= string::un_script_code($class_name);
    $class_number= string::un_script_code($class_number);
    $class_fid=intval($class_fid);
    $class_status= intval($class_status);
    
    //检测必填项目
    if(!$class_name || !$class_number|| !$roster_status)
    {
echo "<script>alert('表单未填完整,带星号为必填项!');history.back();</script>";
exit;    
    }
    
   
    
    //默认参数
    $nowtime=date("Y/m/d H:i:s",time());
    //如果是修改
    if($old_class_id)
    {
 
   $sql = "update class set 
        class_name='$class_name',
        class_number='$class_number',
        class_fid='$class_fid',
        class_status='$class_status',
        edittime='$nowtime'   
        where class_id=$old_class_id";
  $mysql->runSql( $sql );
    }
    else
    {
        //新增
    $sql = "insert into class 
        (class_name,class_number,class_fid,class_status,addtime,edittime,status) 
        values 
        ('$class_name','$class_number','$class_status','$class_fid','$nowtime','$nowtime',1)";
  $mysql->runSql( $sql );
   
    }
    if( $mysql->errno() != 0 )
    {
        echo "<script>alert('".$mysql->errmsg() ."');history.back();</script>";
        exit;
    }
    else
    {
        echo "<script>alert('操作成功!');location='roster_add.php?class_id=$old_class_id';</script>";
        exit;    
    }
    
}    

//获取所有教学楼
$building_list=$mysql->getData("select building_name,building_id from building where status=1 order by building_fid asc");

?>
    

教室添加/修改返回>>


    

带星号为必填项


    
    

        


            *教室名:" name="class_name">
        


        


            *教室人数:" name="class_number">
        


        


            所在教学楼:
            
        


        


            *教室状态:
            
        


         


             
            
            ">
             
            
        


    



回复讨论(解决方案)

1

if(!$class_name || !$class_number|| !$roster_status)    {       echo "<script>alert('表单未填完整,带星号为必填项!');history.back();</Script>";       exit;        }

Copy after login
Copy after login
Copy after login
Copy after login

这里的$roster_status是在哪里被定义和赋值的?你贴出来的代码中没有,页面上的表单中也没有相关的字段,这当然会触发这个验证了

1

if(!$class_name || !$class_number|| !$roster_status)    {       echo "<script>alert('表单未填完整,带星号为必填项!');history.back();</Script>";       exit;        }

Copy after login
Copy after login
Copy after login
Copy after login

这里的$roster_status是在哪里被定义和赋值的?你贴出来的代码中没有,页面上的表单中也没有相关的字段,这当然会触发这个验证了 这个确实是,但更改以后还是有问题,请问是不是还有什么地方有问题啊

var_dump($_POST);


1

if(!$class_name || !$class_number|| !$roster_status)    {       echo "<script>alert('表单未填完整,带星号为必填项!');history.back();</Script>";       exit;        }

Copy after login
Copy after login
Copy after login
Copy after login

这里的$roster_status是在哪里被定义和赋值的?你贴出来的代码中没有,页面上的表单中也没有相关的字段,这当然会触发这个验证了 这个确实是,但更改以后还是有问题,请问是不是还有什么地方有问题啊
你是怎么更改的



1

if(!$class_name || !$class_number|| !$roster_status)    {       echo "<script>alert('表单未填完整,带星号为必填项!');history.back();</Script>";       exit;        }

Copy after login
Copy after login
Copy after login
Copy after login

这里的$roster_status是在哪里被定义和赋值的?你贴出来的代码中没有,页面上的表单中也没有相关的字段,这当然会触发这个验证了 这个确实是,但更改以后还是有问题,请问是不是还有什么地方有问题啊
你是怎么更改的 改成前面定义过的class_status了

var_dump($_POST); 新手求详细

1.$_POST是存放从表单通过post方式提交过来的数据的变量,使用var_dump来打印出这个变量的内部结构,查看下class_status有没有被表单提交,如果有被提交,那么值是什么
2.

1

<select name="class_status">                <option value="0">请选择教室状态</option>                <option <?php if($roster_value["class_status"]==0) echo "selected"?> value="0">空闲</option>                <option <?php if($roster_value["classr_status"]==1) echo "selected"?>  value="1">有课</option>            </select>

Copy after login

这个地方。请选择教室状态和空闲两个option的值都是0,这是不合理的。如果你选择了这两种状态,那么表单提交的class_status就是0,!逻辑非运算符在计算0时得到结果一样是true,因此会触发错误。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles