PHP - Mysql Php Login Problem.
Hello again guys, am having trouble with a login script I have been working on. Have crawled the web for answers so thought i would post here again for some help.
A brief run down on what the script is intended to do: 1.) The script checks to see if a user is logged in, and asks them to if their not. 2.) If theuser is logged in their userid is grabbed from $_SESSION and assigned to $userid 3.) Connection to the database is made and the field premium is updated with value "1" where userid = $userid A error message is supposed to be shown if the query has an error, but currently an error is not produced, the premium field remains NULL and the echo is shown. Can't for the the life of me fiqure out why it isn't working, but i think it is quite simple. Heres my script <?php if (!is_authed()) { echo 'You are not logged-in. Please login so we can add your purchased video to your account.'; include 'login_form.inc.php'; } else { include 'cp/config.php'; include 'cp/opendb.php'; $_SESSION['userid'] = $userid; $query = "UPDATE user SET premium='1' WHERE userid='$userid'"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); echo 'Thank You for purchasing our series. We have added it to your account so you can use it straight away.'; } ?> For some reason the Similar TutorialsI have created a PHP & MySql login but its not working. If I put the right email/password still its showing "Wrong Username or Password" everytime. Bacause I'm beginner to this I don't really know how to solve this issue. Thanks in advance. Here is my coding <?php // Start PHP session at the beginning session_start(); // Create database connection using config file include_once("connection.php"); // If form submitted, collect email and password from form if (isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; // Check if a user exists with given username & password $result = mysqli_query($conn, "select 'Email', 'Password' from tblstudent where Email='$email' and Password='$password'"); // Count the number of user/rows returned by query $user_matched = mysqli_num_rows($result); // Check If user matched/exist, store user email in session and redirect to sample page-1 if ($user_matched > 0) { $_SESSION["email"] = $email; header("location: welcome.php"); } else { echo "User email or password is not matched <br/><br/>"; } } ?> Edited May 4 by Barand code tags added I am using a login system in php and mySQL but only one page is potected. pages i am using: 1. login.php // inputing details (user name, password) 2. checkloginDetails.php // connect to db and check login details 3. logged_in.php // successfully login ...i need more than the one page protected for example; once the user has logged in there will be the main logged in page with other links, remove topics, add, user, remove user all these pages i want protecting but with out the user inputing his details again. Has anyone got an idear onhow i ould achive this? i have already made the register page where their info goes into the database, and im not sure about the code that selects values from the database. mysql_connect('', '', ''); mysql_select_db(''); $user = $_POST['user']; $pass = $_POST['pass']; echo "<font color='white'>You Need To Login</font>"; if($user == Username && $pass == Password) echo "Welcome $user"; mysql_query("SELECT ('Username', 'Password') FROM login"); ?> Ok so I need to create a form to accept the users EmailAddress and Password as credentials to your site then use an SQL Query to determine if the person has an account Code: [Select] <?php require "connectionInfo.php"; $error = ""; if(!isset($_POST["personId"]) || !isset($_POST["firstName"]) || !isset($_POST["lastName"]) || !isset($_POST["emailAddress"]) || !isset($_POST["telephoneNumber"]) || !isset($_POST["socialInsuranceNumber"]) || !isset($_POST["password"]) ) { $error = "Please fill in the info"; } else { if($_POST["personId"] != "" && $_POST["firstName"] != "" && $_POST["lastName"] != "" && $_POST["emailAddress"] != "" && $_POST["telephoneNumber"] != "" &&$_POST["socialInsuranceNumber"] != "" && $_POST["password"] != "") { $dbConnection = mysql_connect($host, $username, $password); if(!$dbConnection) die("Could not connect to the database. Remember this will only run on the Playdoh server."); mysql_select_db($database); $sqlQuery = "INSERT INTO persons (personId, FirstName, LastName, emailAddress, telephoneNumber, socialInsuranceNumber, password) VALUES('".$_POST["personId"]."', '".$_POST["firstName"]."', '".$_POST["lastName"]."', '".$_POST["emailAddress"]."', '".$_POST["telephoneNumber"]."', '".$_POST["socialInsuranceNumber"]."', '".$_POST["password"]."')"; if(mysql_query($sqlQuery)) $error = "Person Successfully Added"; else $error = "Person Could not be added ".mysql_error(); mysql_close($dbConnection); } else $error = "Please enter all the information"; } ?> <form action="createAccount.php" method="post"> Person ID: <input type="text" name="personId" /> <br /> First Name: <input type="text" name="firstName" /> <br /> Last Name: <input type="text" name="lastName" /> <br /> Email: <input type="text" name="emailAddress" /> <br /> Telephone: <input type="text" name="telephoneNumber" /> <br /> Social Insurance Number: <input type="text" name="socialInsuranceNumber" /> <br /> Password: <input type="text" name="password" /> <br /> <input type="submit" value="Submit to Database" /> </form> -----EDIT----- Ok I was able to create the html code for it, but how do I use an sql query to determine if the person has an account? Code: [Select] <form method='post' action='login.php'> <table><tr><td>Email Address:</td><td><input type='text' name='emailAddress'></td></tr> <tr><td>Password:</td><td><input type='password' name='password'></td></tr> <tr><td></td><td><input type='submit' name='submit' value='Log in'></td></tr></table> </form> This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=355401.0 Obviously when connecting to php Im not going to show all of my login details; mysql_connect("details","details","password") or die(mysql_error()); mysql_select_db("details") or die(mysql_error()); whats the best way to hide them? Ive seen some people using an include file with their login details on but say for eg. <?php include('con.php'); ?> Whats to stop somone looking at www.myweb/con.php and obtaining my details there instead? This is my first attemp at a log in system for a website. Everything seems to work fine until the "successful" IF function near the end. All I get it an output of "?>" instead of a redirect to the file "login_success.php". Any help would be GREATLY appreciated!! Tom <?php // Connect to server and select databse. mysql_connect("localhost", "scripts3_public", "sfj123!")or die("cannot connect"); mysql_select_db("scripts3_sfj")or die("cannot select DB"); // username and password sent from form $fusername=$_POST['fusername']; $fpassword=$_POST['fpassword']; // To protect MySQL injection (more detail about MySQL injection) $fusername = stripslashes($fusername); $fpassword = stripslashes($fpassword); $fusername = mysql_real_escape_string($fusername); $fpassword = mysql_real_escape_string($fpassword); $sql="SELECT * FROM `users` WHERE `User name` = '$fusername' AND `Password` = '$fpassword'"; $result=mysql_query($sql); if(!mysql_num_rows($result)) {echo "No results returned.";} // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $fusername and $fpassword, table row must be 1 row if($count==1){ // Register $fusername, $fpassword and redirect to file "login_success.php" session_register("fusername"); session_register("fpassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> I currently have a MyBB forum and I'm going to attempt to create a top list for it, but I'd like users that have already registered on my forum to be able to log into the top list area and either add or edit their website on the top list. How would I go about creating a login script with an already existing MySQL database that contains my MyBB users? I am new to PHP. I have been trying to do some research online for a few days and not getting very far. I feel like I know less now than I did before I started. Here's the story: I've set up a LAMP server that runs a Wiki and AppGini (http://www.bigprof.com/appgini/) - AppGini allows you to "Create web database applications instantly without writing any code" - The only downside we have with it, is it's got it's own set of user accounts. My team all logs in with the default admin account which isn't a big deal but we'd prefer to use LDAP to AD for reasons I won't get into right now. I emailed AppGini support and asked about LDAP integration. Their response was that it's "a little bit of work" and "You can modify the login authentication function to authenticate using LDAP ... please see the example code he http://code.activestate.com/recipes/101525-ldap-authentication/ (needs some modifications to work with AppGini)" I've googled around and found 2 dozen different LDAP PHP samples. I've gotten some of them to work. By work I mean they connect to my domain controller and say "success" I'm not actually logged into anything. So I'm looking for a little help from square one. I need to have a better understanding of how things are supposed to work so I know where I'm supposed to go with all of this. Where do I start? What do I do? What would YOU do? This is the current "index.php" that logs you into the site. Code: [Select] <?php error_reporting(E_ALL ^ E_NOTICE); $d=dirname(__FILE__); include("$d/defaultLang.php"); include("$d/language.php"); include("$d/incCommon.php"); $x->TableTitle=$Translation['homepage']; include("$d/header.php"); if($_GET['signOut']==1){ logOutMember(); } $tablesPerRow=2; $arrTables=getTableList(); ?> <div align="center"><table cellpadding="8"> <?php if($_GET['loginFailed']==1 || $_GET['signIn']==1){ ?> <tr><td colspan="2" align="center"> <?php if($_GET['loginFailed']){ ?> <div class="Error"><?php echo $Translation['login failed']; ?></div> <?php } ?> <form method="post" action="index.php"> <table border="0" cellspacing="1" cellpadding="4" align="center"> <tr> <td colspan="2" class="TableHeader"> <div class="TableTitle"><?php echo $Translation['sign in here']; ?></div> </td> </tr> <tr> <td align="right" class="TableHeader"> <?php echo $Translation['username']; ?> </td> <td align="left" class="TableBody"> <input type="text" name="username" value="" size="20" class="TextBox"> </td> </tr> <tr> <td align="right" class="TableHeader"> <?php echo $Translation['password']; ?> </td> <td align="left" class="TableBody"> <input type="password" name="password" value="" size="20"class="TextBox"> </td> </tr> <tr> <td colspan="2" align="right" class="TableHeader"> <span style="margin: 0 20px;"><input type="checkbox" name="rememberMe" id="rememberMe" value="1"> <label for="rememberMe"><?php echo $Translation['remember me']; ?></label></span> <input type="submit" name="signIn" value="<?php echo $Translation['sign in']; ?>"> </td> </tr> <tr> <td colspan="2" align="left" class="TableHeader"> <?php echo $Translation['go to signup']; ?> <br /><br /> </td> </tr> <tr> <td colspan="2" align="left" class="TableHeader"> <?php echo $Translation['forgot password']; ?> <br /><br /> </td> </tr> <tr> <td colspan="2" align="left" class="TableHeader"> <?php echo $Translation['browse as guest']; ?> <br /><br /> </td> </tr> </table> </form> <script>document.getElementsByName('username')[0].focus();</script> </td></tr> <?php } ?> <?php if(!$_GET['signIn'] && !$_GET['loginFailed']){ if(is_array($arrTables)){ if(getLoggedAdmin()){ ?><tr><td colspan="<?php echo ($tablesPerRow*3-1); ?>" class="TableTitle" style="text-align: center;"><a href="admin/"><img src=table.gif border=0 align="top"></a> <a href="admin/" class="TableTitle" style="color: red;"><?php echo $Translation['admin area']; ?></a><br /><br /></td></tr><?php } $i=0; foreach($arrTables as $tn=>$tc){ $tChk=array_search($tn, array()); if($tChk!==false && $tChk!==null){ $searchFirst='?Filter_x=1'; }else{ $searchFirst=''; } if(!$i % $tablesPerRow){ echo '<tr>'; } ?><td valign="top"><a href=<?php echo $tn; ?>_view.php<?php echo $searchFirst; ?>><img src=<?php echo $tc[2];?> border=0></a></td><td valign="top" align="left"><a href=<?php echo $tn; ?>_view.php<?php echo $searchFirst; ?> class="TableTitle"><?php echo $tc[0]; ?></a><br /><?php echo $tc[1]; ?></td><?php if($i % $tablesPerRow == ($tablesPerRow - 1)){ echo '</tr>'; }else{ echo '<td width="50"> </td>'; } $i++; } }else{ ?><tr><td><div class="Error"><?php echo $Translation['no table access']; ?><script language="javaScript">setInterval("window.location='index.php?signOut=1'", 2000);</script></div></td></tr><?php } } ?> </table><br /><br /><div class="TableFooter"><b><a href=http://bigprof.com/appgini/>BigProf Software</a> - <?php echo $Translation['powered by']; ?> AppGini 4.61</b></div> </div> </html> Hey there,
First time using MySQL database to connect to a member login. I have a paid subscription site through ccbill which they add the username and logins to. I have setup a database, username and password as well as a table that I have connected correctly "I believe" to my website but get this message: warning: MySQL-fetch_array()expects parameter 1 to be resource, Boolean given in /home....
My table I have setup just has username and password to authenticate the users, which I was told by ccbill is all I need. Maybe I need authentication 1 or 0 etc.
Any help on this would be amazing. Spent hours trying to figure this out but nothing.
Thanks for your time.
Steven
I am currently creating a multi-user login system, and I have created the database in MySQL, but the problem is that my PHP script is not working as expected. I would like it so that if the user enters in a correct username + password combination, then they are redirected to a webpage called "congrats.php" for example. However, with my current PHP code, if I include a redirection instruction based on the correct input, then when I run the script, then the user is instantly taken to the congrats.php page without filling in any login details. I'm quite sure that the database has been connected to, as due to the layout of my script at the moment, the text that reads "You did it!" appears 4 times, the same number of rows in my MySQL database. My PHP coding for this is: Code: [Select] <html><head><title>Multi-User Log In Form</title></head> <body> <?php $self = $_SERVER['PHP_SELF']; $username = $_POST['username']; $password = $_POST['password']; ?> <form action = "<?php echo $self; ?>" method = "post"> Username <input type = "text" name = "username" size = "8"> Password <input type = "password" name = "password" size = "8"> <input type = "submit" value="Submit"> </form> <?php $conn = @mysql_connect("localhost", "root", "") or die ("Err: Conn"); $rs = @mysql_select_db("test3", $conn) or die ("Err: Db"); $sql = "select * from users"; $rs = mysql_query($sql, $conn); while ($row = mysql_fetch_array($rs)) { $name = $row["uname"]; $pass = $row["pword"]; if ($username = $name && $password = $pass) { //CODE FOR REDIRECTION SHOULD GO HERE //header("location:congrats.php"); echo "You did it!"; } else { echo "Invalid username and password combination"; } } ?></body> </html> Any help in trying to get it so that my PHP script will redirect only if a correct username + password combination is entered would be greatly appreciated Hello All, I have this problem, no matter if I typed the wrong or right email and password, I always get Login failed message here is my code index.php Code: [Select] <td class="white-text">Email: <form name="form1" method="post" action="/admin/Login.php"> <label for="user"></label> <input type="text" name="email" /> </td> </tr> <tr> <td><p><strong class="white-text">Password:</strong></p> <label for="sdf"></label> <input type="password" name="password" /> <p class="sdf"><strong></strong><a href="#" class="white-link-underline"><strong></strong></a> <input type="submit" name="submit" id="submit" value="Submit" /> </p> </form> </td> Login.php Code: [Select] <?php session_start(); $con = mysql_connect("localhost","123","123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("123", $con); if (isset($_POST['email'])) { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); //Query $results = mysql_query("SELECT * FROM users WHERE 'email' = '$email' AND password = '$password' "); if(!$result) { $_SESSION['error'] = '<span style="color: red">Login Failed. Email or Password is Incorrect <br/>'; } else { $row = mysql_fetch_assoc($results); $_SESSION['userid'] = $row['id']; $_SESSION['email'] = $email; $_SESSION['error'] = 'Login Successful<br/>. Welcome,'. $email; } mysql_close($con); } header('Location: ./index.php') ?> Hello there, The problem is that my login system isn't consistent. There's an option of staying logged in, and if you check that a cookie gets created with a hash. When you visit the site again, you should be logged in automatically. But the thing is, that when you load the page, you aren't! But after a refresh you are logged in. So I'm guessing a problem in the order of things that get done... Here's the script: Code: [Select] <?php session_start(); if(isset($_COOKIE['LoginCookie'])) { $hash = $_COOKIE['LoginCookie']; mysql_select_db('database'); $sql = "SELECT all the info of the people FROM people WHERE cookie_hash = '".$hash."'"; if($result = mysql_query($sql)) { $row = mysql_fetch_array($result); if(empty($row)) { setcookie('LoginCookie','',time()-3600); } if(mysql_num_rows($result) == 1) { $_SESSION['loggedin'] = true; $_SESSION['loggedinnick'] = $row['nick']; $_SESSION['loggedinvoornaam'] = $row['voornaam']; $_SESSION['loggedinachternaam'] = $row['achternaam']; $_SESSION['loggedinid'] = $row['id']; $_SESSION['loggedintype'] = $row['type']; } } } if(isset($_POST['login'])) { if(empty($_POST['username']) || empty($_POST['wachtwoord'])) { $_SESSION['melding'] = 'ERROR'; header('Location: index.php'); exit(); } $username = CleanMyDirtyData($_POST['username']); $wachtwoord = sha1(CleanMyDirtyData($_POST['wachtwoord'])); mysql_select_db('database'); $sqlmail = mysql_query("SELECT * FROM people WHERE email='$username' AND wachtwoord = '$wachtwoord'"); $sqlnaam = mysql_query("SELECT * FROM people WHERE nick='$username' AND wachtwoord = '$wachtwoord'"); if(mysql_num_rows($sqlmail) == 1 || mysql_num_rows($sqlnaam) == 1) { if(mysql_num_rows($sqlmail) == 1) { $row = mysql_fetch_array($sqlmail); } else { $row = mysql_fetch_array($sqlnaam); } if(isset($_POST['remember'])) { $hash = sha1($username . 'Some secret thingys for your safety'); setcookie('LoginCookie',$hash,time()+30000000); mysql_query("UPDATE leden SET cookie_hash='" . $hash . "' WHERE id='" . $row['id'] . "'")or die(mysql_error()); } $_SESSION['loggedin'] = true; $_SESSION['loggedinnick'] = $row['nick']; $_SESSION['loggedinvoornaam'] = $row['voornaam']; $_SESSION['loggedinachternaam'] = $row['achternaam']; $_SESSION['loggedinid'] = $row['id']; $_SESSION['loggedintype'] = $row['type']; $_SESSION['melding'] = 'You are logged in now.'; } else { $_SESSION['melding'] = 'ERROR'; header('Location: index.php'); exit(); } } So if the checkbox that you want to stay logged in, there is no cookie made but the $_SESSION['loggedin'] is set to true. Throughout the rest of the page, this parameter is used to show either content for guests of private content for people that are logged in. BUT the problem is that if it is checked on the first page load the $_SESSION['loggedin'] doesn't seem to get set even though the cookie is set. Another slight problem with my script is that when a user logs in on another pc, the hash get's changed in the database and the user gets logged out of the site on the previous page. What is the easiest way to do that? And do you guys think this script is safe? Or do you see some holes? Thanks in advance! arbitter login system. why wont it work? Did same thing @ school it worked. this is my action page: <?php ob_start(); $host="host"; // Host name $username="user"; // Mysql username $password="pass"; // Mysql password $db_name="db"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "users/index.php" session_register("myusername"); session_register("mypassword"); header("location:users/index.php"); } else { echo "Error. Username or password incorrect. Have you <a href='#' onclick='alert()'>registered?</a>"; } ob_end_flush(); ?> It comes up with this error: Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\external\index.php:59) in C:\xampp\htdocs\external\action.php on line 32 Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\external\index.php:59) in C:\xampp\htdocs\external\action.php on line 32 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\external\index.php:59) in C:\xampp\htdocs\external\action.php on line 34 If you have not registered, please click here Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0 Good day! I have an index.php or a login page.The scenario on my webpage is when i successfully login and i accidentally press the back button the login page appear again and when i try to login again i could login again, which is not good. here is my code: <?php session_start(); if(isset($_SESSION['USER_ID'])){ exit("you can't login in again when your all ready logged!"); } //require_once 'conn.php'; $db_name="dspi"; mysql_connect("localhost", "root", "") or die("Cannot connect to server"); mysql_select_db("$db_name")or die("Cannot select DB"); $department = mysql_real_escape_string($_POST['department']); $username = mysql_real_escape_string($_POST['username']); $sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error()); $ct = mysql_num_rows($sql); if($ct == 1) { $row = mysql_fetch_assoc($sql); if($row['Department']=='Accounting') { header('location: Company.php'); } elseif($row['Department']=='Engineering') { header('location: Company.php'); } elseif($row['Department']=='Finishing_Goods') { header('location: Company.php'); } elseif($row['Department']=='HRAD') { header('location: Company.php'); } elseif($row['Department']=='MIS') { header('location:Company.php'); } elseif($row['Department']=='Packaging_and_Design') { header('location:Company.php'); } elseif($row['Department']=='Production') { header('location:Company.php'); } elseif($row['Department']=='Purchasing_Logistic') { header('location:Company.php'); } elseif($row['Department']=='QA_and_Technical') { header('location:Company.php'); } elseif($row['Department']=='Supply_Chain') { header('location:Company.php'); } else { header('location:index.php'); echo"Incorrect Username or Department"; } } ?> Hi, I had my login working and now it has stopped working. Idk why but heres the files: <?php ob_start(); include 'inc/open.php'; // Define $ip and $password $ip=$_POST['ip']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $ip = stripslashes($ip); $password = stripslashes($password); $ip = mysql_real_escape_string($ip); $password = mysql_real_escape_string($password); $sql="SELECT * FROM status WHERE ip='$ip' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $ip and $password, table row must be 1 row if($count==1){ // Register $ip, $password and redirect to file "login_success.php" session_register("ip"); session_register("password"); header("location:lindex.php"); } else { echo "Wrong ip or Password"; } ob_end_flush(); ?> And then I want my index page to recognize this and do the following: <?php session_start(); include('inc/open.php'); if(session_is_registered('ip')){ echo "<h5><a href='index.php'>Home</a> | <a href='addnew.php'>Add New Sever</a> | <a href='offline.php'>View Offline Servers</a> | <a href='editserver.php'>Server CP</a></h5>"; }else{ echo "<h5><a href='index.php'>Home</a> | <a href='addnew.php'>Add New Sever</a> | <a href='offline.php'>View Offline Servers</a> | <a href='editlogin.php'>Login</a></h5>"; } ?> Thank you. Problem: the login is working and redirecting to index.php however index.php is not recognizing that user is logged on. i want help as i cant find that the reason that why registered members cant login, when user pass entered it does not process any thing any help will be appreciated Code: [Select] <?php session_start(); session_register("id_session"); session_register("password_session"); include "header.php"; include "config.php"; $a=""; $b=""; if ($_POST) { $a=trim($_POST["id"]); $b=trim($_POST["password"]); $a=str_replace("'","",$a); $b=str_replace("'","",$b); $a=str_replace("\"","",$a); $b=str_replace("\"","",$b); } if ($a=="" || $b=="") { if ($_SESSION["id_session"]=="" || $_SESSION["password_session"]=="") { ?> <form action=members.php method=post> <br><br><Center><table><tr><td colspan=2 align=center><h3>Members Login Area</h3></td></tr> <tr><td>Member's ID</td><td><input type=text name=id></td></tr> <tr><td>Password</td><td><input type=password name=password></td></tr> <tr><td> </td><td> <a href="forgot.php" onclick="doexit=false;"><font face="Verdana,Arial,Helvetica" size="1" color="#000000"><b>Forgot Your Password?</b></font></a></td></tr> <tr><td colspan=2 align=center><input type=submit value="Log In"></td></tr> </table></form> <? } else { middle(); } } else { $check=0; $id=$_POST["id"]; $rs = mysql_query("select * from members where ID='$id'"); if ($rs) { $arr=mysql_fetch_array($rs); $n2=$arr['Password']; if ($n2==$b) { $check=1; $_SESSION["id_session"]=$arr[0]; $_SESSION["password_session"]=$arr[9]; middle(); } } if ($check==0) { print "<h2>Invalid User Id or Password</h2>"; ?> <form action=members.php method=post> <br><br><Center><table><tr><td colspan=2 align=center><h3>Members Login Area</h3></td></tr> <tr><td>Member's ID</td><td><input type=text name=id></td></tr> <tr><td>Password</td><td><input type=password name=password></td></tr> <tr><td> </td><td> <a href="forgot.php" onclick="doexit=false;"><font face="Verdana,Arial,Helvetica" size="1" color="#000000"><b>Forgot Your Password?</b></font></a></td></tr> <tr><td colspan=2 align=center><input type=submit value="Log In"></td></tr> </table></form> <? } } function middle() { $id=$_SESSION["id_session"]; $rs = mysql_query("select * from members where ID=$id"); $arr=mysql_fetch_array($rs); $check=1; $id=$arr[0]; $password=$arr[9]; $name=$arr[1]; $address=$arr[2]; $city=$arr[3]; $state=$arr[4]; $zip=$arr[5]; $country=$arr[6]; $phone=$arr[7]; $email=$arr[8]; $password=$b; $paymentoption=$arr[10]; $refby=$arr[11]; $l1=$arr[12]; $l2=$arr[13]; $l3=$arr[14]; $l4=$arr[15]; $l5=$arr[16]; $l6=$arr[17]; $l7=$arr[18]; $l8=$arr[19]; $l9=$arr[20]; $l10=$arr[21]; $leader=$arr[22]; $total=$arr[23]; $unpaid=$arr[24]; $paid=$arr[25]; ?> <table border="0" width="650"> <tr> <td width="150" valign="top"> <table width="140"> <tr> <td align="left"><br><br><br><br> <ul><font face="verdana" size="1"> <a href="stats.php">Statistics</a><br><br> <a href="update_pf.php">Edit Personal Information</a><br><br> <a href="sample_e.php">Referral Code & Links</a><br><br> <a href="logout.php">Logout</a><br><br> </td></tr></table> </td> <td VALIGN="top"> <table> <tr> <td> <font face="verdana" size="3"><b> <p>Account Center</b></font></p> <br> </td> </tr> <tr> <td> <div align="center"> <table border="0" cellpadding="3" cellspacing="0" width="400"> <tr> <td colspan="2"><b> <hr><font face="Verdana, Arial, Helvetica, sans-serif" size="-1"><center> Account Details for <?echo $name;?></font></center></b><hr> </td> </tr> <tr> <td valign="center" align="left"><strong><font face="Verdana" size="-1">Total Commisions Earned: </font></strong><br></td> <td valign="center"> <font face="Verdana" size="-1">$<? echo $total;?></font><br></td> </tr> <tr> <td valign="center" align="left"><strong><font face="Verdana" size="-1">Commisions Due: </font></strong><br></td> <td valign="center"> <font face="Verdana" size="-1">$<? echo $unpaid;?></font><br></td> </tr> <tr> <td valign="center" align="left"><strong><font face="Verdana" size="-1">Commisions Paid: </font></strong><br></td> <td valign="center"> <font face="Verdana" size="-1">$<? echo $paid;?></font><br></td> </tr> <tr> <td valign="center" align="left" colspan=2> </td> </tr> <tr> <td valign="center" align="left"><strong><font face="Verdana" size="-1">Direct Referrals: </font></strong><br></td> <td valign="center"> <font face="Verdana" size="-1"><? $rsd=mysql_query("select * from members where Leader=".$id); echo mysql_num_rows($rsd); ?></font><br></td> </tr> <tr> <td valign="center" align="left" colspan=2> </td> </tr> <tr> <td valign="center" align="left" colspan=2><strong><font face="Verdana" size="3">Downline Information </font></strong><br></td> </tr> <tr> <td valign="center" align="left"><strong><font face="Verdana" size="-1">Total Downline Size: </font></strong><br></td> <td valign="center"> <font face="Verdana" size="-1"><? echo ($l1+$l2+$l3+$l4+$l5+$l6+$l7+$l8+$l9+$l10); ?></font><br></td> </tr> <tr><td colspan=2> <Table width=100%> <tr><td bgcolor=#000000><strong><font face="Verdana" size="-1" color=#ffffff>Level</font></strong></td> <td bgcolor=#000000><strong><font face="Verdana" size="-1" color=#ffffff>Number of Members</font></strong></td> </tr> <? include "config.php"; ?> <? for($i=1;$i<=$levels;$i++) { ?> <tr><td><strong><font face="Verdana" size="-1"><? echo $i; ?></font></strong></td> <td ><font face="Verdana" size="-1"> <? if($i==1) { echo $l1; } elseif($i==2) { echo $l2; } elseif($i==3) { echo $l3; } elseif($i==4) { echo $l4; } elseif($i==5) { echo $l5; } elseif($i==6) { echo $l6; } elseif($i==7) { echo $l7; } elseif($i==8) { echo $l8; } elseif($i==9) { echo $l9; } elseif($i==10) { echo $l10; } ?> </font></td> </tr> <? } ?> </table> </td></tr> <tr><td colspan=4><hr></td><tr> </table> </div> </td> </tr> </table> <font face="verdana" size="3"><b> <p>Download Center</b></font></p> <? include "download.php"; ?> </td> </tr> </table> <br><br> <? } include "footer.php"; ?> edit: added [code][/code] blocks Hi, below is the error and php that i used for my login page.
Error:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 11 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 11 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 12 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 12 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 13 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 13 Php: <?php //session_start(); $today = date(Ymd); $_SESSION[username] = $_POST['username']; $_SESSION[password] = $_POST['password']; $_SESSION[id] = $_POST['id']; $username = stripslashes($_SESSION[username]); $password = stripslashes($_SESSION[password]); $username = mysql_real_escape_string($_SESSION[username]); $password = mysql_real_escape_string($_SESSION[password]); $id = mysql_real_escape_string($_SESSION[id]); include('connection.php'); $sql_login = "SELECT id FROM admin WHERE username = '$username' and password = '$password'"; $result_login = mysql_query($sql_login); $count_login = mysql_num_rows($result_login); //$row = mysql_fetch_assoc($sql_login); if($count_login == 1) { //session_register("user_email"); //session_register("user_password"); //echo "PASS"; header("location:../admin/main_admin.php"); } else { header("location:admin_login2.php"); } exit; ?> I have a login script which is showing problem. The problem is that when my username and password are correct it directs to index.php page and displays the correct username there. But if the password is wrong it still directs to the same page instead of different(err-login.php) page,but this time no username is displayed. index.php: the password verifying code is as follows(the whole code of index.php is not mentioned since it is too long and a bit messy) <code> <?php $connection=mysql_connect("localhost","root",""); mysql_select_db("forum",$connection); $select=mysql_query("SELECT * FROM user_id WHERE uname='$_REQUEST[uname]'",$connection); $row=mysql_fetch_array($select); if($row['password']==$_REQUEST['password']){ session_start(); $_SESSION['name']=$_REQUEST['uname']; } else{ header("Location:err-login.php"); } ?> </code> NOTE:-The name of my db and table are correct. I have referred to username as uname. |