farkewie Posted November 6, 2007 Share Posted November 6, 2007 Cool, If everything is working please topic solved. Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 but it is not working, It is saying i can;t view the page even when i enter in the Right info. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 <?php $email = $_COOKIE['email']; $sql = "SELECT username FROM players WHERE email='$email' "; $sql = mysql_query($sql); $row = mysql_fetch_assoc($sql); $username = $row['username']; if (!isset($username)) { echo "you are not allowed to acces this page"; exit; } else { echo "Logged in as ".$username; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2007 Share Posted November 6, 2007 Post your current code. Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 main.php <!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>Untitled Document</title> <link href="style1.css" rel="stylesheet" type="text/css" /> </head> <body> <?php include "include/db.php"; ?> <?php $email = $_COOKIE['email']; $sql = "SELECT username FROM players WHERE email='$email' "; $sql = mysql_query($sql); $row = mysql_fetch_assoc($sql); $username = $row['username']; if (!isset($username)) { echo "you are not allowed to acces this page"; exit; } else { echo "Logged in as ".$username; } ?> </body> </html> login.php <!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=iso-8859-1" /> <title>Login</title> <link href="style1.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="post" action="loginck.php" target="_parent"> <p align="center"> <span class="style2">Enter Email:</span> <br> <input type="text" name="email" id="email"> <br> <span class="style2">Enter Passowrd:</span><br> <input type="password" name="password"> <br> <input name="Submit" type="submit" class="top" value="Submit"> </p> <p align="center"> </p> <p align="center"> </div> <strong>Messages:</strong> </p> </p> <div align="center">Working on</div> </body> </html> loginck.php <? session_start(); ?> <?php //include "include/db.php"; ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <link href="style1.css" rel="stylesheet" type="text/css"> <title></title> </head> <body> <?php include "include/db.php"; $email = $_POST['email']; $password = $_POST['password']; $check = mysql_query("select * from players where email='$email'"); $check1 = mysql_query($check); $row = mysql_fetch_assoc($check); $db_user = $row['email']; $db_password = $row['password']; if (!$db_user) { $message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head> <p class=\"errortext\"><strong>$email</strong> is not in the database...</p>"; } // give error if user exists but wrong password else if (($db_user)&& ($password !== $db_password)) { $message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head> <p class=\"errortext\"> Your password is wrong...</p>"; } else if (($db_user) && ($password == $db_password)){ setcookie ("email",$email,+3600); print "<script>"; print " self.location='main.php';"; print "</script>"; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 This may be it . its on logincheck.php <?php $check = mysql_query("select * from players where email='$email'"); $check1 = mysql_query($check); $row = mysql_fetch_assoc($check); ?> should be <?php $check = mysql_query("select * from players where email='$email'"); if ($result = mysql_query($check)) { if ($row = mysql_fetch_assoc($result)) } } else { echo mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 <?php if ($row = mysql_fetch_assoc($result)) } ?> What goes in that statement? I am alst getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1 Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 <?php $check = mysql_query("select * from players where email='$email'"); if ($result = mysql_query($check)) { if ($row = mysql_fetch_assoc($result)){ echo "user logged in"; } } else { echo mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1 Still get that error. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 can you configm what page this is on and try evhoes $email before the sql query? echo $email; Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 can you configm what page this is on and try evhoes $email before the sql query? echo $email; it is on lohinck.php, and yes i can echo the email, and the password Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 $check = "SELECT * FROM players where email='$email'"; Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 on main.php. It does not let me acess the page. Even if i enter the right Login info. Would someone be able to Give me. or Direct me to some login Code, that acctuly Works, and is easy to understand Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 You are better off fixing this one as you are nearly there and can learn for next time. if you look at the db in phpmyadmin does it have a field called username? and how are the password storedplain text or encrypted? Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 I do have a feild called username, And They are just plain text. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 change the cookie to this it all i can think of. sorry setcookie("email",$db_user, time()+3600); /* expire in 1 hour */ Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 change the cookie to this it all i can think of. sorry setcookie("email",$db_user, time()+3600); /* expire in 1 hour */ nope sorry still doesn;t work I have run out of idea for this, and it proberly the most simply thing as well >.>...proberly a Missing Semi Colon Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2007 Share Posted November 6, 2007 Your login.php page can remain the same. However, here is an example of what your loginck.php should look like. You never actually set any $_SESSION variables, so there is no login. <?php session_start(); include "include/db.php"; if (isset($_POST['Submit'])) { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $sql = "SELECT username FROM players WHERE email='$email'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['username'] = $row['username']; header("Location: main.php"); } } } ?> Now, your main.php should look like.... <?php session_start(); ?> <!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>Untitled Document</title> <link href="style1.css" rel="stylesheet" type="text/css" /> </head> <body> <?php if (!isset($_SESSION['username'])) { echo "<p>you are not allowed to acces this page</p>"; } else { echo "<p>Logged in as {$_SESSION['username']}</p>"; } ?> </body> </html> Hope that helps. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 6, 2007 Share Posted November 6, 2007 ok just going to check the really basics...lol when you fill out the login for your entering your email address not username? you dont have any special charsin the password the code isnt miss types because we are not getting errors. its doing what its supposed to do and not let you in if it cant authenticate.. double check everything look at the querys and make sure you are passing the right details to them. Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 usesing thorpe's code i get this error Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Athina\loginck.php:19) in C:\wamp\www\Athina\loginck.php on line 32 Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2007 Share Posted November 6, 2007 make sure there is no output (or whitespace) in your db.php file. Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 <? $hostname="localhost"; $mysql_login="USERNAME"; $mysql_password="PASSWORD"; $database="athina"; if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){ die("Can't connect to mysql."); }else{ if (!(mysql_select_db("$database",$db))) { die("Can't connect to db."); } } ?> that is my db.php, i can;t see any problem with it. Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2007 Share Posted November 6, 2007 Is there any blank lines outside of the <? ?> tags? ps: You should always use <?php ?> tags. Quote Link to comment Share on other sites More sharing options...
Ads Posted November 6, 2007 Author Share Posted November 6, 2007 No Blank Spaces Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2007 Share Posted November 6, 2007 Well, there is output somewhere, you'll need to make sure there is no output (including any whitespace) prior to any session_start(); calls. 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.