我正在尝试创建一个登录表单,在该登录表单中我使用fetch_array()方法来获取用户输入的字段,但它显示了一些错误:
的login.php
<?php
include ("Connection.php");
?>
<?php
if(isset($_POST['Login']))
{
$Em = $_POST['form-email'];
$Pw = $_POST['form-password'];
$result = $con->query("SELECT * FROM userdetails where Email='$Em' Password='$Pw'");
$row = $result->fetch_assoc(MYSQLI_BOTH);
session_start();
$_SESSION["UserID"] = $row['UserID'];
header('Location: index.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GTEC Registration Form Template</title>
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/form-elements.css">
<link rel="stylesheet" href="assets/css/style.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicon and touch icons -->
</head>
<body>
<!-- Top content -->
<div class="top-content">
<div class="inner-bg">
<div class="container">
<div class="row">
<div class="col-sm-7 text">
<h1><strong>GTEC Network</strong> Registration Form</h1>
<div class="description">
<p class="jumbotron">
To be a premier Institution of choice in the region and become one of the leading educational Institutions in the country widely recognized for providing high quality, transformative and affordable value based education in the field of Engineering and Technology.
</p>
</div>
<div class="top-big-link">
<a class="btn btn-link-2" href="registrer.php">Sign Up!</a>
</div>
</div>
<div class="col-sm-5 form-box">
<div class="form-top">
<div class="form-top-left">
<h3>Login</h3>
<p>Fill in the form below to get instant access:<br/>
Once you login your account ,<br/>
You can access gtec network thereby you can view ur syllabus,timetable,updates,
internal marks,results,also you can ur forum for many purpose</p>
</div>
<div class="form-top-right">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form role="form" action="" method="post" class="Login-form">
<div class="form-group">
<label class="sr-only" for="form-email">Email</label>
<input type="email" name="form-email" placeholder="Email..." class="form-email form-control" id="form-email">
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Email</label>
<input type="password" name="form-password" placeholder="Password..." class="form-password form-control" id="form-password">
</div>
<button type="submit" class="btn" name="Login">Login!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Javascript -->
<script src="assets/js/jquery-1.11.1.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script src="assets/js/retina-1.1.0.min.js"></script>
<script src="assets/js/scripts.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"></script>
<![endif]-->
</body>
</html>
的index.php
<?php session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>GTEC NetWork</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/business-frontpage.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php echo $_SESSION['UserID'];?>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">GTEC NetWork</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Services</a>
</li>
<li>
<a href="#">Contact</a>
</li>
<li>
<a href="#"></a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Image Background Page Header -->
<!-- Note: The background image is set within the business-casual.css file. -->
<header class="business-header">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="tagline">GTEC Student Info System</h1>
</div>
</div>
</div>
</header>
<!-- Page Content -->
<div class="container">
<hr>
<div class="row">
<div class="col-sm-8">
<h2>What We Do</h2>
<p>Introduce the visitor to the business using clear, informative text. Use well-targeted keywords within your sentences to make sure search engines can find the business.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et molestiae similique eligendi reiciendis sunt distinctio odit? Quia, neque, ipsa, adipisci quisquam ullam deserunt accusantium illo iste exercitationem nemo voluptates asperiores.</p>
<p>
<a class="btn btn-default btn-lg" href="#">Call to Action »</a>
</p>
</div>
<div class="col-sm-4">
<h2>Contact Us</h2>
<address>
<strong>Start Bootstrap</strong>
<br>3481 Melrose Place
<br>Beverly Hills, CA 90210
<br>
</address>
<address>
<abbr title="Phone">P:</abbr>(123) 456-7890
<br>
<abbr title="Email">E:</abbr> <a href="mailto:#">name@example.com</a>
</address>
</div>
</div>
<!-- /.row -->
<hr>
<div class="row">
<div class="col-sm-4">
<img class="img-circle img-responsive img-center" src="http://placehold.it/300x300" alt="">
<h2>Marketing Box #1</h2>
<p>These marketing boxes are a great place to put some information. These can contain summaries of what the company does, promotional information, or anything else that is relevant to the company. These will usually be below-the-fold.</p>
</div>
<div class="col-sm-4">
<img class="img-circle img-responsive img-center" src="http://placehold.it/300x300" alt="">
<h2>Marketing Box #2</h2>
<p>The images are set to be circular and responsive. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.</p>
</div>
<div class="col-sm-4">
<img class="img-circle img-responsive img-center" src="http://placehold.it/300x300" alt="">
<h2>Marketing Box #3</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.</p>
</div>
</div>
<!-- /.row -->
<hr>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
这是登录表单和index.php,我已经创建了寄存器表单,它工作得很好,我注册的数据存储正确,但问题是登录表单,它是重定向到索引页面,错误是:
致命错误:在第13行的C:\ xampp \ htdocs \ Studentmanagementsys \ Login.php中的非对象上调用成员函数fetch_assoc()
答案 0 :(得分:1)
您的SQL查询中存在语法错误。当你通过mysqli执行查询时,如果有一些sql语法错误,方法$ con&gt; query(...)将返回布尔值false
。因此,您false
的值为$result
。
Php cant对布尔值的调用方法:$result->fetch_assoc()
,因为boolean是标量值,而不是对象。 (对不起我的英文)