php - 在 div 中调用 php 函数
问题描述
我想在 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ña Modificada <br> <a href='index_alumnos.php' >Iniciar Sesion</a>";
} else {
echo "Error al modificar contraseña";
}
} else {
echo "Las contraseñas no coinciden <br> <a href='index_alumnos.php' >contacta a Academia</a>";
}
?>
解决方案
If the echo happens before your actual div is drawn, the echo goes... right where it happens. Which isn't within your div.
One way of getting around this would be to put your error message into a variable and then deliver this variable into your div (whether it be through a return
value, if it's a call, or some other means.)
Here's a simple example to illustrate this:
<?php
if(1 === 2) {
//great, 1 is 2
} else {
//oh no, an error
$someErrorLine = '1 is not 2';
} ?>
<h1>Hi</h1>
<div><?= $someErrorLine ?></div>
You could also check if the variable exists, something like if(isset($someErrorLine)) {} and echo the div with it, or put the div within your variable.
推荐阅读
- hadoop - Pig 作业因“org.apache.hadoop.mapreduce.counters.LimitExceededException:太多计数器:121 max=120”而失败
- ionic4 - 如何在 ionic 4 中隐藏 onScroll 标题?
- bash - 如何在 Unix 中将文件移动到名称相似的文件夹中?
- apache-kafka - Kafka 到 kafka 在 krb5 安全性背后使用 Gobblin
- perforce - `p4 where`的输出中前导的“-”(破折号)是什么意思?
- regex - 如何从终端中的文件运行 perl 正则表达式列表
- mysql - 使用 $Lookup 将 MYSQL 查询转换为 mongodb
- javascript - 没有私有方法的 Angular 组件
- r - Rstats - 如何将公里转换为弧度以使用 {sf} / {units} 创建缓冲区?
- json - react js中未定义错误landig.Slots的类型