Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在div中调用php函数_Php_Html - Fatal编程技术网

在div中调用php函数

在div中调用php函数,php,html,Php,Html,我想在一个html div中调用这个php逻辑,但是当将它作为函数传递时,逻辑会中断,因为在输入错误的密码以及在执行密码更改时确认密码的情况下,它不会发送错误消息 <?php require 'funcs/conexion.php'; require 'funcs/funcs.php'; $user_id = $mysqli->real_escape_string($_POST['user_id']); $token = $mysq

我想在一个html div中调用这个php逻辑,但是当将它作为函数传递时,逻辑会中断,因为在输入错误的密码以及在执行密码更改时确认密码的情况下,它不会发送错误消息

<?php
    
    require 'funcs/conexion.php';
    require 'funcs/funcs.php';
    
    $user_id = $mysqli->real_escape_string($_POST['user_id']);
    $token = $mysqli->real_escape_string($_POST['token']);
    $password = $mysqli->real_escape_string($_POST['password']);
    $con_password = $mysqli->real_escape_string($_POST['con_password']);
    

    if(validaPassword($password, $con_password))
    {
        $pass_hash = hashPassword($password);
        
        if(cambiaPassword($pass_hash, $user_id, $token))
        {
            echo "Contrase&ntilde;a Modificada <br> <a href='index_alumnos.php' >Iniciar Sesion</a>";
            } else {
            echo "Error al modificar contrase&ntilde;a";
        }
        } else {
        echo "Las contraseñas no coinciden <br> <a href='index_alumnos.php' >contacta a Academia</a>";
    }
?>  

如果回显发生在绘制实际div之前,则回显将。。。就在它发生的地方。这不在你的分区内

解决这一问题的一种方法是将错误消息放入变量中,然后将此变量传递到div中(无论是通过
返回值,如果是调用,还是其他方式)

下面是一个简单的例子来说明这一点:

<?php
if(1 === 2) {
    //great, 1 is 2
} else {
    //oh no, an error
    $someErrorLine = '1 is not 2';
} ?>

<h1>Hi</h1>
<div><?= $someErrorLine ?></div>

你好

您还可以检查变量是否存在,比如if(isset($someErrorLine)){}并用它回显div,或者将div放在您的变量中。

可能会添加htmlHi GibranQ,您尝试过什么吗?