Php 如果用户已在数据库上注册,则无法获取登录以重定向到主页
我似乎无法将我的登录页面链接到我的主页,任何帮助都将不胜感激。我知道它连接到数据库,因为我可以创建用户,但出于某种原因,它不允许我使用创建的用户登录Php 如果用户已在数据库上注册,则无法获取登录以重定向到主页,php,html,forms,mysqli,Php,Html,Forms,Mysqli,我似乎无法将我的登录页面链接到我的主页,任何帮助都将不胜感激。我知道它连接到数据库,因为我可以创建用户,但出于某种原因,它不允许我使用创建的用户登录 <?php require ("insert.php"); ?> <?php if(isset($_POST[ 'Login' ])) { $email= mysqli_real_escape_string($con, $_POST ['email']); $pswrd= mysqli_real_e
<?php require ("insert.php"); ?>
<?php
if(isset($_POST[ 'Login' ]))
{
$email= mysqli_real_escape_string($con, $_POST ['email']);
$pswrd= mysqli_real_escape_string($con, $_POST ['pswrd']);
$result = $con->query (" select * from users where email='$email' AND pswrd='$pswrd' ");
$row = $result->fetch_array(MYSQLI_BOTH);
session_start();
$_SESSION["User ID"] = $row['UserID'];
header ('Location: home.php');
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>AMSadler login</title>
<meta charset="utf-8">
<meta name="description" content="description of webpage">
<meta name="keywords" content="keywords go here">
<meta name="author" content="Anthony">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/login.css">
<link rel="index" href="index.php">
<link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png">
</head>
<body>
<div class="header">
<div id="logo">
<a href="index.html"><img src="img/logo.png" alt="logo" title="AMSadler.com"/></a>
</div>
<div id="signup">
<button type="button"><a href="signup.php">Sign up</a></button>
</div>
</div>
<div id="login">
<form>
<input type="text" name="email" placeholder="Email address">
<br>
<input type="password" name="password" placeholder="Password">
<br>
<input id="Login" type="submit" name="Login" value="Login">
</form>
</div>
<footer>
<div id="copyright">
<p>© Copyright 2015</p>
</div>
</footer>
</body>
</html>
您需要更改表单标签
从
对,
您需要指定方法
类型,以便在PHP
代码中可以使用该方法获得它。如果省略了方法
部分,则默认情况下它使用$\u GET
。当代码指向$\u POST
时,将其设置为method=“POST”
您还需要设置action=”“
,对于同一页面,可以将其设置为#
,也可以将其留空或使用文件名。这会将表单重定向到该页面。表单默认为省略某个方法时会发生什么?哦,天哪,我真不敢相信我错过了这一点。非常感谢,我是新来的this@AnthonySadler没问题。很高兴我能帮忙。如果我的答案对您有帮助,请单击绿色勾号。同一页面为空不#@Script47检查查询是否返回结果,因为现在所有人都可以登录:)嗯,它正在工作。但是,现在,当我重定向到我的主页,并在代码中放置一个echo语句,在我的页面中,它不工作。有任何建议吗?
<form>
<form action="yourPageName.php" method="post">