首页 > 解决方案 > 在同一个表单页面中成功提交表单后如何显示图像?

问题描述

我创建了一个包含表单的页面,我想在成功提交表单后显示隐藏在同一页面中的图像,我正在尝试使用 PHP 代码中的 JavaScript 来实现。

这是代码

html代码:

        <label for="UserEmail">Email</label> &nbsp&nbsp&nbsp&nbsp&nbsp
        <input type="text" name="UserEmail" placeholder="Enter Email"><br><br>
        <label for="UserEmail">Password</label>
        <input type="password" name="UserPass" placeholder="Enter Password"><br><br>
        <input type="submit" value="Log in">&nbsp&nbsp
        <button>click</button>
        <a href="securityQ.html">Forgot password</a>&nbsp&nbsp
        <a href="register.html">New !! register </a>
        <div id="imge">
            <img src="profile.png" alt="Profile Image">
        </div>
    </form>

PHP代码:

<?php
error_reporting(0);
$x ="hi";
$y ="1";
if(($_POST["UserEmail"]==$x) and ($_POST["UserPass"]==$y))
{ 
    echo "<script>
        document.getElementById('img').style.display='block';
        </script>";
        header("location: index.html");
}
else {
    echo "<script>alert('Login Faild');window.location.href='index.html';</script>";
    }
?>

标签: javascriptphphtmlforms

解决方案


你必须使用jQuery和ajax来提交表单,当你提交表单并在数据库中插入数据并将图像上传到文件夹中时,然后返回该图像的位置,在jQuery的成功方法中,使用该图像位置来显示使用 jQuery 选择器在任何特定元素上显示图像并使该元素可见


推荐阅读