I have the following code bellow that will check to see if the user is available in the database before he is granted access to the site however when the user enters any value it will log him in even if he is not registered in the data base. After this code there is JQuery code that i also used to prevent any value from being enterd into that database if the field is empty and it is not the default text field value. however whenever the i login i am still begin prompt to enter a valid text and it continues to the login process rather then stopping me from doing anything before i fill the required field.
<?php
if(isset($_SESSION["owner"])){
header("Location:index.php");
exit();
}
?>
<?php
require_once("includes/connection.php");
if(isset($_POST["username"]) && isset($_POST["password"])){
$owner = $_POST["username"];
$password = $_POST["password"];
$query = "SELECT id FROM users WHERE username = '$owner' AND password ='$password' LIMIT 1";
$sql = mysql_query($query,$connection);
$existCount = mysql_num_rows($sql);
if($existCount == 1){
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
}
$_SESSION["id"] =$id;
$_SESSION["owner"] = $owner;
$_SESSION["password"] =$password;
echo"welcome back" .$owner."<a href=\"index.php\"> please continue</a>";
exit();
}
else{
header("Location:login.php");
exit();
}
}
require_once("includes/header.php");
?>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=3.2.1'></script>
<script type='text/javascript' src='/bobs/admin/javascript/login.js'></script>
<div class="cBoth"></div>
<div id="sep"></div>
<div class="Calign">
<div id="formcontent">
<div class="flotr">
<h2>Book faster every time</h2>
<br/>
<p class="widthis">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</p>
</div><!-- end of flotr div text --->
<div class="flotr">
<div id="errordisplay"></div>
<fieldset class="spacing">
<form method="post" action="admin/formProc/formproc.php" id="frmnewuser">
<h2>New to Travelnstay ?</h2>
<p class="widthis">A Travelnstay account is required to continue.</p>
<p class="formsp">Username</p>
<p><label><input type="text" name="username" height="15px" value="Username "id="username"/><label></p>
<p class="formsp">Email</p>
<p><label><input type="text" name="email" value="Your Email" id="email"/><label></p>
<p class="formsp">Re-email</p>
<p><label><input type="text" name="reemail" value="Retype your Email" id="reemail"/><label></p>
<p class="formsp">Password</p>
<p><label><input type="password" name="password" id="password"/><label></p>
<p class="formsp">Re-password</p>
<p><label><input type="password" name="repassword" id="repassword" /><label></p>
<p class="formsp"><label><input type="submit" name="newuser" value="SING ME UP"/><label></p>
</form>
</fieldset>
</div><!-- end of flotr div sign up--->
<div class="flotl">
<fieldset class="spacing">
<form method="post" action="login.php">
<h2>Sign in</h2>
<p class="widthis">You need to log in to access your account.</p>
<p class="formsp">Username</p>
<p><input type="text" name="username" value="username" id="usernamelog"/></p>
<p class="formsp">Password</p>
<p><input type="password" name="password" /></p>
<p></p>
<p class="formsp"><label><input type="submit" name="login" value="Login"/><label></p>
</form>
</fieldset>
</div><!-- end of flotl div login--->
</div>
</div>
<div class="cBoth"><!-- clear Both--></div>
<!--<script src="/bobs/admin/javascript/formscript.js"></script>-->
<?php require_once("includes/footer.php"); ?>
The next line is the JQuery code.
$(document).ready(function(){
//this will waip out anyhting in that text field.
$("#usernamelog").click(function(){
$(this).val("");
$(this).css("color","#741863");
});
$("input:submit").click(function(){
var username = $("#usernamelog").val();
if((username == "")||(username == "username")){
alert("Please enter a valid username");
}
});
});