usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 <code> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Home</title> <link rel="stylesheet" href="imgs/style.css"/> </head> <body> <!--Main Div Tag--> <div id="wrapper"> <div id="header"> <div id="logo"><img src="imgs/Logo/Logo.png" alt=""/> </div> <div id="Searchbar"> <div id="box1"><input type="text" size="30" name="name" style="background-color:transparent;" /></div> </div> <div id="magnify"> <a href=""/><img src="imgs/Log In/magnify.png" alt=""/></div> </div> <div> <a id="Home" href="index.html" title="Home"><span>Home</span></a> <a id="Photoshop" href="Photoshop.html" title="Photoshop"><span>Photoshop</span></a> <a id="Illustrator" href="Illustrator.html" title="illustrator"><span>illustrator</span></a> <a id="Tips" href="Tips.html" title="Tips"><span>Tips</span></a> <a id="AboutUs" href="About Us.html" title="AboutUs"><span>About Us</span></a> </div> <div id="main"> <div id="header1"><img src="imgs/Homepage tuts/Homepage Main/Newtuts.png" alt=""/></div> <div id="header2"><img src="imgs/Log In/login.png" alt=""/> <?php $username = $_POST["username"]; $password = $_POST["password"]; //This if statement asks if the $username variable is set. If it is it executes the php script. Otherwise it echoes the login form. if(isset($username)){ if ($username&&$password) { $connect = mysql_connect("mysql13.000webhost.com","a3073051_shakoor","usman1") or die("Couldn't connect!"); mysql_select_db("a3073051_login") or die("Couldn't find db"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //check to see if they match if ($username==$dbusername&&$password==$dbpassword) { echo "You're in!"; } else echo "incorrect password!"; } else die("That user does not exist!"); } else die("Please enter a username and password!"); } //This next bit echoes the login form unless the $username variable is set. else { echo ('<div id="username"> <form action="" method="post"/> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } ?> </div> <div id="table1"> <table><tr><td> <a href="imgs/Homepage tuts/Create a HD Television.html"><img src="imgs/Homepage tuts/Homepage Main/Homepage Tutorials/TVtut/icon1.png" alt=""/></a> </td><td> <a href="imgs/Homepage tuts/tut2.html"><img src="imgs/Homepage tuts/Homepage Main/Homepage Tutorials/tut2/icontut2.png" alt=""/></a> </td></tr></table> <table><tr><td> <a href="imgs/Homepage tuts/tut3.html"><img src="imgs/Homepage tuts/Homepage Main/Homepage Tutorials/tut3/tut3icon.png" alt=""/></a> </td><td> <a href="imgs/Homepage tuts/tut4.html"><img src="imgs/Homepage tuts/Homepage Main/Homepage Tutorials/tut4/tut4icon.png" alt=""/></a> </td></tr></table> <table><tr><td> <a href="imgs/Homepage tuts/tut5.html"><img src="imgs/Homepage tuts/Homepage Main/Homepage Tutorials/tut5/tut5icon.png" alt=""/></a> </td><td> <a href="imgs/Homepage tuts/tut6.html"><img src="imgs/Homepage tuts/Homepage Main/Homepage Tutorials/tut6/tut6icon.png" alt=""/></a> </td></tr></table> </div> </div> <div id="footer"> <div id="footernav"> <a id="fHome" href="index.html" title="Home"><span>Home</span></a> <a id="fPhotoshop" href="Photoshop.html" title="Photoshop"><span>Photoshop</span></a> <a id="fillustrator" href="Illustrator.html" title="illustrator"><span>illustrator</span></a> <a id="fTips" href="Tips.html" title="Tips"><span>Tips</span></a> <a id="fAboutUs" href="About Us.html" title="AboutUs"><span>About Us</span></a> </div> </div> </div> </body> </html> </code> Quote Link to comment Share on other sites More sharing options...
Jacbey Posted January 3, 2012 Share Posted January 3, 2012 Here you go, this should work. Just replace all of the previous php with this and put your password and username for the database back in: <?php $username = $_POST["username"]; $password = $_POST["password"]; //This if statement asks if the $username variable is set. If it is it executes the php script. Otherwise it echoes the login form. if(isset($username)){ if (!($username == " " && $password == " ")) { $connect = mysql_connect("mysql13.000webhost.com","retracted","retracted") or die("Couldn't connect!"); mysql_select_db("a3073051_login") or die("Couldn't find db"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); $dbusername = $row['username']; $dbpassword = $row['password']; } else { echo ('<div id="username"> <form action="" method="post"/> <font face="Lucinda" color="red"> Please supply a username and password </font> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } //check to see if they match if ($username == $dbusername && $password == $dbpassword) { echo "You're in!"; } else echo ('<div id="username"> <form action="" method="post"/> <font face="Lucinda" color="red"> Wrong username or password, please try again </font> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } //This next bit echoes the login form unless the $username variable is set. else { echo ('<div id="username"> <form action="" method="post"/> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } ?> Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 ok i did that, now the text 'Wrong username or password, please try again' is displayed at all times, and if i do type in the correct username and password,nothing happens and the text ,Wrong username or password, please try again,is still displayed Quote Link to comment Share on other sites More sharing options...
Jacbey Posted January 3, 2012 Share Posted January 3, 2012 ok i did that, now the text 'Wrong username or password, please try again' is displayed at all times, and if i do type in the correct username and password,nothing happens and the text ,Wrong username or password, please try again,is still displayed What is the web link so I can see what is happening? Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 The link: http://adobetuts.netai.net/ Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 thats weird! i thort id test the link and on there it works? lol Quote Link to comment Share on other sites More sharing options...
Jacbey Posted January 3, 2012 Share Posted January 3, 2012 Right, I figured it out. DO the same thing as last time. Here = <?php $username = $_POST["username"]; $password = $_POST["password"]; //This if statement asks if the $username variable is set. If it is it executes the php script. Otherwise it echoes the login form. if(isset($username)){ if (!($username == " " && $password == " ")) { $connect = mysql_connect("mysql13.000webhost.com","retracted","retracted") or die("Couldn't connect!"); mysql_select_db("a3073051_login") or die("Couldn't find db"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $row = mysql_fetch_array($query); $numrows = mysql_num_rows($query); $dbusername = $row['username']; $dbpassword = $row['password']; } else { echo ('<div id="username"> <form action="" method="post"/> <font face="Lucinda" color="red"> Please supply a username and password </font> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } //check to see if they match if ($username == $dbusername && $password == $dbpassword) { echo "You're in!"; } else echo ('<div id="username"> <form action="" method="post"/> <font face="Lucinda" color="red"> Wrong username or password, please try again </font> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } //This next bit echoes the login form unless the $username variable is set. else { echo ('<div id="username"> <form action="" method="post"/> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } ?> The problem was that it wasn't actually fetching an array ($row = mysql_fetch_array($query) so I added that in and it should work. Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 actually no,it keeps showing up with 'Wrong username or password, please try again' even tho the username and password is correct, also if i put a random user in, it should say 'user does not exist' but it doesnt? Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 iv tried that,nearly there now! lol its does say come up with 'your in' when username and password is correct but the 'incorrect password' and 'user does not exist' dont show when they meant too? Quote Link to comment Share on other sites More sharing options...
Jacbey Posted January 3, 2012 Share Posted January 3, 2012 It should work fine. :/ I've got to go out for about twenty minutes I'll be back in a bit. Perhaps we could chat over Skype? Might be easier. Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 Oh ok, im afraid i dont have skype, but really appreciate ur help. I would have never got this far, thank you. Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 If i click on login with entering anything,it logs in...how do i stop it doing that?thx Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 i mean, if i select 'log in' without entering any username or password, it logs in. how do i stop it from doing that? thx Quote Link to comment Share on other sites More sharing options...
Jacbey Posted January 3, 2012 Share Posted January 3, 2012 Don't worry, it's fine. Okay, I've double and triple checked this - <?php $user = $_REQUEST['username']; $pass = $_REQUEST['password']; $subm = $_REQUEST['submit']; if(empty($user) || empty($pass)) { echo ('<div id="username"> <form action="" method="post"/> <font face="Lucinda" color="red"> Please supply a username and password. </font> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } else { if(isset($subm)){ $myServer = "mysql_server"; $myUser = "username"; $myPass = "password"; $myDB = "database_name"; //connection to the database $dbhandle = mysql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $selected = mysql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); $query = "SELECT * FROM spotty WHERE username = '" . $user . "' AND password = '" . $pass ."'"; $result = mysql_query($query) or die('Error Getting user_info'); $row = mysql_fetch_array($result); if($user == $row['username'] && $pass == $row['password']){ echo "You're in!"; } else { echo ('<div id="username"> <form action="" method="post"/> <font face="Lucinda" color="red"> Wrong username and password. </font> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } } else { echo ('<div id="username"> <form action="" method="post"/> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" id="submit" name="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } } ?> Quote Link to comment Share on other sites More sharing options...
usman07 Posted January 3, 2012 Author Share Posted January 3, 2012 when on website, the message 'please supply a username and password' is displayed, and it doesnt do anything when i type in the correct details Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2012 Share Posted January 3, 2012 The current (previously posted) code will 'log you in' when nothing has been entered because an empty string is equal to an empty string and the code is not really checking if anything was entered. It's actually checking if anything other than a space was entered and an empty string is something other than a space. The current (previously posted) logic contains many issues. You need to slow down and first define what you want to do, then write and test the code needed to perform each step that you have defined. Edit: The latest code posted also contains coding issues, such as not repeating the form code three times that only differ in an error message being displayed. That makes a wall of code. What happens when you want to change the look or layout of the form? You have to find and make the change three times. The form is also invalid (two <form > tags) and doesn't have a field named 'submit', so the posted code still won't work. Recommendation - slow down when defining, writing, and testing code. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 3, 2012 Share Posted January 3, 2012 And please, when posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.