gpt4 book ai didi

php - 基于php if语句在div中添加/更改文本

转载 作者:太空宇宙 更新时间:2023-11-04 15:13:55 25 4
gpt4 key购买 nike

我有一个创建新用户的页面。我有一个 php 脚本,它对文本字段中输入的数据进行各种检查。当它发现不符合要求的条目时,我需要向用户提供反馈以说明流程终止的原因。我的想法是简单地有一个空的 div,我将用一条特定于失败条件的消息填充它。

然而,看起来这可能比我想象的要难。我更愿意在我的 php 脚本中这样做。我对网络开发还很陌生。我愿意接受有关实现此目标的最佳/最简单方法的建议。谢谢。

<div id="page">
<img id="mainpic" src="images/banner.png" height="390" width="982">

<div id="stylized" class="leftsidebox"></div>

<div id="stylized" class="myform">
<form id="form" name="form" method="post" action="scripts/create_admin.php">

<label>Security Code
<span class="small">Enter the security code provided to you</span>
</label>
<input type="text" name="securitycode" id="name" />

<button type="submit">Create Administrator</button>
</form>
</div>

<div id="stylized" class="rightsidebox">
<div id="stylized" class="feedback">
<h1>this is where I want to add dynamic text from php</h1>
</div>

</div>
</div>


<?php

include('connection.php');

//retrieve input values from the form
$security_code = $_REQUEST['securitycode'];

if (strlen($security_code) == 0) {
//Add the text "Please enter a security code." to the div class="feedback"
die();
}
?>

最佳答案

在html之前添加php代码

<?php

include('connection.php');

//retrieve input values from the form
$security_code = $_REQUEST['securitycode'];

if (strlen($security_code) == 0) {
$error="Please enter a security code.";
//Add the text "Please enter a security code." to the div class="feedback"
die();
}
?>

<div id="stylized" class="feedback">
<h1><?php if(isset($error)){ echo $error; } ?></h1>
</div>

关于php - 基于php if语句在div中添加/更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17373365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com