【发布时间】:2014-01-19 19:33:42
【问题描述】:
我是一名大学商科学生,正在尝试建立一个具有商业模式的网站。
我正在构建一个允许用户注册的网站。现在我正在使用 action: signup.php 将用户存储到数据库中。成功插入用户后,我将页面重定向回提交表单的 index.html。
我的问题是,如何通过我的 PHP 标记引用 JavaScript 将登录从 display:block 更改为 display:none 并从 display:none 注册确认到 display:block?
我目前正在使用$_GET 从signup.php 中获取成功/失败状态,并且我想使用IF 语句来执行正确的JavaScript 代码。
更新
我被建议改为将所有 div 设置为阻止并使用 PHP IF 语句来显示登录或注册 div。但是,实施更改后,index.html 仍然无法区分成功/失败状态。下面是我的代码:
注册.php:
if (mysqli_num_rows($data) == 0)
{
$qry = "INSERT INTO logins (username, password, email) VALUES ('$username', SHA('$password1'), '$email')";
$result=mysqli_query($dbc, $qry);
if($result)
{
header('Location: index.html?signup=success');
}
}
else
{
header('Location: index.html?signup=fail');
}
index.html:头部
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Site</title>
<link type="text/css" rel="stylesheet" href="home.css">
<script type="text/javascript">...</script>
<?php
if(!empty($_GET['signup']))
{
$signup = $_GET['signup'];
}
?>
</head>
index.html:正文
<body>
<div id="container">
<?php
if(!$signup)
{
?>
<div id="login">...</div>
<?php
}
?>
<?PHP
if($signup)
{
?>
<div id="signedup">...</div>
<?PHP
if($signup == 'success')
{
?>
<div id="confirmation">...</div>
<?php
}
?>
<?PHP
if($signup == 'fail')
{
?>
<div id="failure">...</div>
<?php
}
?>
<?php
}
?>
</div>
</body>
截至目前,在用户提交表单后,它们被插入到数据库中。问题是一旦它们被重定向到 index.html,php 就无法识别成功/失败状态,因此只显示登录表单。
【问题讨论】:
标签: javascript php forms redirect confirmation