Gazz1982 Posted June 4, 2008 Share Posted June 4, 2008 Hi im trying to get the user name of a user when they login. The user enters their email and password how do I then use this to ask the mysql database for their first name? see www.noblesweb.co.uk email= a password= b this info is displayed at the top of the page using: <?php session_start(); Print_r ($_SESSION); ?> how do I use it in this query: $result = mysql_query("SELECT * FROM login WHERE EMAIL=' '"); I want the email to be what is contained in the Array [myusername] Array ( [myusername] => b [mypassword] => a ) Thanks Gazz Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/ Share on other sites More sharing options...
p2grace Posted June 4, 2008 Share Posted June 4, 2008 Is the email address being saved into the session? Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557621 Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 You are using form to have them log in? Grab the $_POST variable and use it in your query. Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557623 Share on other sites More sharing options...
Gazz1982 Posted June 4, 2008 Author Share Posted June 4, 2008 Im getting the login details from a form using: $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; then registering the session: session_register("myusername"); session_register("mypassword"); so will this work? $result = mysql_query("SELECT * FROM login WHERE EMAIL='$_POST['myusername']'"); Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557629 Share on other sites More sharing options...
runnerjp Posted June 4, 2008 Share Posted June 4, 2008 yes but only on that page... i would store username into a session... then you can call it on every page i do something like this <?php function get_username ( $id ) { global $db; $query = "SELECT `Username` FROM `users` WHERE `ID` = " . $db->qstr ( $id ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); return $row->Username; } else { return FALSE; } } then you can just grab a username via the session... btw also it confused me a little when you say email = a password = b but the sessions are [myusername] => b [mypassword] => a Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557644 Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 Yep, unless their email is their username, dunno. Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557656 Share on other sites More sharing options...
runnerjp Posted June 4, 2008 Share Posted June 4, 2008 but by what its saying the password is the username and the email is the password... think somethings wrong benith the surface there Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557663 Share on other sites More sharing options...
Jabop Posted June 4, 2008 Share Posted June 4, 2008 $_SESSION['logged']['user']=""; $_SESSION['logged']['email']=""; Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557665 Share on other sites More sharing options...
Gazz1982 Posted June 4, 2008 Author Share Posted June 4, 2008 >but by what its saying the password is the username and the email is the password... think somethings wrong benith the surface there I've turned something around - need to sort it out later. I'm still a bit confused - sorry im a beginner My database = register table = login columns = EMAIL|PASSWORD|NAME_FIRST|NAME_LAST ........ so when they login using: <form class='small' name='login' method='post' action='checklogin.php?<?php echo SID?>'> <p class='small'> Email<input name='[color=red]mypassword[/color]' type'text' id='mypassword' size='13'></p> <p class='small'> Password <input name='[color=red]myusername[/color]' type='text' id='myusername' size='9'></p> <p class='small'><a href='register.php?<?php echo SID?>' > Register </a> <input type='submit' name='Submit' value='Login' /></p> </form> Then this goes to Connect to database + $myusername=$_POST['email']; $mypassword=$_POST['password']; $sql="SELECT * FROM $tbl_name WHERE email='$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 "login_success.php" session_register("email"); session_register("password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } Then this goes to <? session_start(); if(!session_is_registered(myusername)){ header("location:login_fail.php"); }else{ header("location:index.php"); } ?> Then this goes to the home page So how do I ammend this so that the email becomes a global variable which I can use in this query: $sql="Select * from login where EMAIL='________' "; Thanks for your patience and help Gazz Link to comment https://forums.phpfreaks.com/topic/108739-displaying-user-name/#findComment-557923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.