我们被要求创建一个网站,我想问一下我的表单是否有问题,因为无论何时我在浏览器上打开它总是会在我的html结束标记上出错。
<?php
session_start();
include('connect.php');
?>
<?php
if (isset($_POST['Login'])){
$username=$_POST['username'];
$password=$_POST['password'];
$login_query=mysql_query("select * from user where username='$username' and password='$password' and Usertype='admin'") or die(mysql_error());
$login_query1=mysql_query("select * from user where username='$username' and password='$password' and Usertype='user'") or die(mysql_error());
$count=mysql_num_rows($login_query);
$count1=mysql_num_rows($login_query1);
$row=mysql_fetch_array($login_query);
$row1=mysql_fetch_array($login_query1);
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="mystylelogin.css">
</head>
<body style="background-color: #66A9EB">
<header>
<div class="header"><h1><a href="login.php">Tidbits<a></h1></div>
<div class="header-cont">
</header>
<form method="POST" action="home.php">
<fieldset>
<p> Welcome </p>
<br>
Username: <input type="text" name="uname">
<br><br><br>
Password: <input type="password" name="pword">
<br>
<div id="button">
<br>
<input type="submit" style="font-family: Verdana; color: white; font-size: 20px; background-color: #99CCFF; border: 1px solid #3399FF; border-radius:5px; margin-left: 150px" name="do" value="Log In"/>
</div>
<div>
<P>
</div>
<p id="create"><a href="register.php">Create an Account</a></p>
<?php
if($count == 1){
$_SESSION['id']=$id;
header('Location: admin.php');
}
if($count1 == 1){
session_start();
$_SESSION['id']=$id;
header('location:user.php');
}
?>
</fieldset>
</form>
<!----------------------------------SLIDESHOW------------------------------------------------------->
<script type="text/javascript">
var slideimages = new Array() // create new array to preload images
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "cookiesandcream.jpg" // set image src property to image path, preloading image in the process
slideimages[1] = new Image()
slideimages[1].src = "pizza.jpg"
slideimages[2] = new Image()
slideimages[2].src = "waffle.jpg"
</script>
</head>
<body>
<img src="cookiesandcream.jpg" id="slide" width="700" height="500" />
<script type="text/javascript">
//variable that will increment through the images
var step=0
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.getElementById('slide').src = slideimages[step].src
if (step<2)
step++
else
step=0
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",2500)
}
slideit()
</script>
</body>
</html>
你可以告诉我代码上的错误吗?
答案 0 :(得分:1)
header
必须位于页面顶部
将其移至doctype标记上方:
if($count == 1){
$_SESSION['id']=$id;
header('Location: admin.php');
}
if($count1 == 1){
// session_start(); ---------- remove this line as you already started the session at the top of the page
$_SESSION['id']=$id;
header('location:user.php');
}
您错过了打开html
标记:
<!DOCTYPE html>
<html>
您尚未关闭初始if (isset($_POST['Login'])){
- 您需要结束}
您还需要在初始幻灯片演示脚本之后删除以下标记:
</head>
<body>
答案 1 :(得分:0)
你的意思是你得到的消息是你的HTML无效吗?您的起始<html>
标记丢失了。
正确的标记如下所示:
<!DOCTYPE html>
<html>
<head>
<title>Some Website</title>
</head>
<body>
…
</body>
</html>
答案 2 :(得分:0)
您缺少第一个if语句末尾的结束花括号。
正确的缩进将有助于在将来发现这些错误,如果您遇到问题,您无法通过php验证程序尝试运行代码,例如http://phpcodechecker.com/