We were asked to create a website, I would like to ask if there's something wrong with my form because whenever I open it on my browser it always gets an error on my html end tag.
<?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>
can you please tell me the error on my codes?
Do you mean you get a message that your html is invalid? Your starting <html>
tag is missing. Correct markup looks like this:
<!DOCTYPE html>
<html>
<head>
<title>Some Website</title>
</head>
<body>
…
</body>
</html>
You are missing the closing curly bracket from the end of the first if statement.
Proper indentation would help immensely in spotting these errors in the future and if you have problems you can't spot try running the code through a php validator, such as http://phpcodechecker.com/
header
has to be at the top of the page before any output is done (before you start your html)
move this to the to above the doctype tag:
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');
}
You have missed you opening html
tag:
<!DOCTYPE html>
<html>
And you haven't closed the initial if (isset($_POST['Login'])){
- you need a closing }
You also need to remove the following tags from after your initial slideshow script:
</head>
<body>