我收到此错误:
警告:mysql_fetch_array()要求参数1为资源,第9行的?/config.php中给出布尔值
代码:
<!-- Config.php Code -->
<?php session_start();
//mysql connection
$con = mysql_connect("localhost","digmoorc","community20");
mysql_select_db("digmoorc_EHUB",$con);
function getUserData($userID) {
$query=mysql_query("select 'userID' from tbl_users where userID=$userID limit 1");
while($row = mysql_fetch_array($query))
if ($query === false) mysql_error();
{
}
}
?>
答案 0 :(得分:0)
在这种情况下,您必须在行尾找到缺少的分号,并且缺少右括号。
在这种情况下,你的第一个if子句
if(isset($_POST['Submit'])) {
未关闭。所以没有关闭}。
答案 1 :(得分:0)
试试这个
<?php
require("config.php");
$error = '';
if(isset($_POST['Submit'])) {
$userName=$_POST['userName'];
$passWord=$_POST['passWord'];
$query=mysql_query("select user ID from tbl_users where userName='$userName' and passWord='$passWord' limit 1");
if(mysql_num_rows($query)==1) {
//login success
$data=mysql_fetch_array($query,1);
$_SESSION['userID']=$data['userID'];
header("location:dashboard.php");
exit();
}else{
//login failed
$error="Invalid Login";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" type="image/png" href="#" />
<!--META DATA -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<link rel="credits" type="rel" href="http://www.cultivatecreative.co.uk/" />
<!-- STYLESHEETS -->
<style>
body {
background: #e8f5f6;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-rendering: optimizeLegibility;
font-weight: normal;
color: #444;
padding-top: 39px;
-webkit-tap-highlight-color: #62A9DD;
}
#header {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 39px;
padding: 0;
background: #59c5c4;
-moz-box-shadow:inset 0 0 10px #2f6b8f;
-webkit-box-shadow:inset 0 -5px 10px #2f6b8f;
box-shadow:inset 0 0 10px #2f6b8f;
}
#wrapper {
width: 540px;
margin: 100px auto;
padding: 30px;
background: #fff;
}
a.logo {
margin: 18px auto 30px;
display: block;
width: 244px;
height: 107px;
background: url(file:///C|/Users/Daniel/Downloads/Evermore%20HUB/evermoorhub-logo.png) no-repeat;
text-indent: -9999px;
border: none;
}
h1 {
text-align: center;
font-size: 2.833em; /* 22px */
font-family: arial, sans-serif;
color: #444;
font-weight: normal;
color: #59c5c4;
}
a {
color: #000;
text-decoration: none;
}
a:hover {
border-bottom: none;
}
p {
text-align: center;
font-size: 1em; /* 22px */
font-family: arial, sans-serif;
color: #000;
font-weight: normal;
color: #000;
}
#wrapper table {
background-color: #59c5c4;
}
</style>
<title>Evermoor HUB | Login</title>
</head>
<body>
<div id="header"></div>
<div id="wrapper">
<a class="logo" href="http://www.evermoorhub.co.uk" title="Webpage design:">Daniel Woods</a>
<h1><strong><center>User Login</center></strong></h1>
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="1" class="table">
<?php if(isset($error)); ?>
<td colspan="2" align="center"><strong class="error"><?php echo $error; ?></strong></td>
</tr>
<td width="50%" align="right">Username:</td>
<td width="50%"><input name="userName" type="text" id="userName"></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="passWord" id="passWord"></td>
</tr>
<tr>
<td align="right"> </td>
<td><input type="submit" name="Submit" id="Submit" value="Submit"></td>
</tr>
</table>
</form>
</div> <!-- Wrapper -->
</body>
</html>