klaroen Posted June 17, 2006 Share Posted June 17, 2006 Oke, I got this little login script but their seems to be something wrong about superglobals.. [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] [b]Objective[/b]I want that the user who logges in is stored in a session and I can get his information by connecting with my database with the session[b]The scripts I now have[/b]### login.php ###----------------------<?php session_start();if ($Submit) { $DBHost = "localhost"; $DBLogin = "klaroen_data"; $DBPassword = "******"; $DBDatabase = "klaroen_data"; mysql_connect("$DBHost", "$DBLogin", "$DBPassword"); @mysql_select_db("$DBDatabase"); $LoginNaam = addslashes($LoginNaam); $LoginPassword = addslashes($LoginPassword); $LoginMail = addslashes($LoginMail);$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'"); $Results = mysql_num_rows($Query); if ($Results == '1') { $_SESSION['login'] = "1"; header ("Location: base.php"); } else { header ("Location: wronglogin.php"); }}?>----------------------### base.php (page after login.php) ###-------------------------------------------------<?php session_start(); if ($_SESSION['Login'] == "1") {?> <?php$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['Login']."'";$st=mysql_query($query);$recs=mysql_num_rows($st);$row=mysql_fetch_assoc($st); print <<<ENDHTML <table width="100%"> <tr> <td width="50%" valign="top" style="padding-right: 25px;"> <table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0"> <tr> <th colspan="2" align="center">User Info</th> </tr> <tr> <td><b>Name</b> </td> <td>$row->username</td> </tr> </table> </td> </tr> </table>ENDHTML;?><?php } else { include("mustlogin.php"); }?> -------------------------------------------------------What must I do to let it work to display his informations??($row->username == doesn't work)!!!HELP! Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/ Share on other sites More sharing options...
redarrow Posted June 17, 2006 Share Posted June 17, 2006 ('$submit');isset(['submit']);$_POST(['submit']);[code]database connectionselect database WHERE id='$id'";$result=mysql_query($query);while($row=mysql_fetch_assoc($result) {echo $row['name'];}[/code] Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46714 Share on other sites More sharing options...
klaroen Posted June 17, 2006 Author Share Posted June 17, 2006 But I haven't got the $id from anywhere... Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46715 Share on other sites More sharing options...
redarrow Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo(post=385027:date=Jun 17 2006, 05:54 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 05:54 PM) [snapback]385027[/snapback][/div][div class=\'quotemain\'][!--quotec--]But I haven't got the $id from anywhere...[/quote][code]<td>$row->username</td>to<td><? echo$row['username'];?></td>[/code]my code is an example ok. Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46717 Share on other sites More sharing options...
klaroen Posted June 17, 2006 Author Share Posted June 17, 2006 But my sessions aren't working proper either!If I loggin and get redirected to base.phpI'm not allowed (so not logged in..) Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46721 Share on other sites More sharing options...
redarrow Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo(post=385033:date=Jun 17 2006, 06:13 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 06:13 PM) [snapback]385033[/snapback][/div][div class=\'quotemain\'][!--quotec--]But my sessions aren't working proper either!If I loggin and get redirected to base.phpI'm not allowed (so not logged in..)[/quote]Chage the submit code ok like this or an example above.[code]if ('$Submit') {[/code] Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46727 Share on other sites More sharing options...
klaroen Posted June 17, 2006 Author Share Posted June 17, 2006 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/klaroen/domains/kingsofwar.be/public_html/kocclone/base.php on line 108...DAMN! :p Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46740 Share on other sites More sharing options...
redarrow Posted June 17, 2006 Share Posted June 17, 2006 login.php[code]<?php session_start();// connect to database.$DBHost = "localhost";$DBLogin = "klaroen_data";$DBPassword = "******";$DBDatabase = "klaroen_data";mysql_connect("$DBHost", "$DBLogin", "$DBPassword");@mysql_select_db("$DBDatabase");// if theres a post submit.if ($_POST(['submit'] ) ) {$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'");$Results = mysql_num_rows($Query);// if user exists goto base.phpif ($Results == '1') {session_register('email');session_register('name');session_rgister('password')header ("Location: base.php");}else{header ("Location: wronglogin.php");}}?>[/code]base.php[code]//if session exists.<?php session_start();if ( (! $_SESSION['username'] )&& (! $_SESSION['password'])) {?>//select with while loop.<?php$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['username']."' and password='".$_SESSION['password']."' ";$st=mysql_query($query);while($row=mysql_fetch_assoc($st)){?><table width="100%"><tr><td width="50%" valign="top" style="padding-right: 25px;"><table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0"><tr><th colspan="2" align="center">User Info</th></tr><tr><td><b>Name</b></td><td><? echo $row['username']; ?></td></tr></table></td></tr></table><?}?><?php//if not logged in goto correct page.}else{header("location: mustlogin.php ");}?> [/code] Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46745 Share on other sites More sharing options...
klaroen Posted June 17, 2006 Author Share Posted June 17, 2006 Look, I use these print<<<ENDHTML and ENDHTML; thingsso how must I print my name now?like so?: <td> $row['username'] </td> ??? Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46748 Share on other sites More sharing options...
redarrow Posted June 17, 2006 Share Posted June 17, 2006 Try the code above trying my best here ok. Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46757 Share on other sites More sharing options...
klaroen Posted June 17, 2006 Author Share Posted June 17, 2006 isn't it "while($row=mysql_fetch_assoc($st)){" in stat of "while($row=mysql_fetch_assoc($st){ ???ANDif ((! $_SESSION['username'] )&& ($_SESSION['password'])) { in stat of if ((! $_SESSION['username'] )&& $_SESSION['password'])) {??? Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46762 Share on other sites More sharing options...
redarrow Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo(post=385074:date=Jun 17 2006, 07:53 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 07:53 PM) [snapback]385074[/snapback][/div][div class=\'quotemain\'][!--quotec--]isn't it "while($row=mysql_fetch_assoc($st)){" in stat of "while($row=mysql_fetch_assoc($st){ ???ANDif ((! $_SESSION['username'] )&& ($_SESSION['password'])) { in stat of if ((! $_SESSION['username'] )&& $_SESSION['password'])) {???[/quote]correct my fault sorry. Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46763 Share on other sites More sharing options...
klaroen Posted June 17, 2006 Author Share Posted June 17, 2006 lol , (thanks for the help) , but here is the next error:Parse error: syntax error, unexpected '[', expecting ')' in /home/klaroen/domains/kingsofwar.be/public_html/kocclone/login.php on line 18and line 18 says: if ($_POST(['submit'] ) {so.... Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46765 Share on other sites More sharing options...
redarrow Posted June 17, 2006 Share Posted June 17, 2006 login.php[code]<?php session_start();// connect to database.$DBHost = "localhost";$DBLogin = "klaroen_data";$DBPassword = "******";$DBDatabase = "klaroen_data";mysql_connect("$DBHost", "$DBLogin", "$DBPassword");@mysql_select_db("$DBDatabase");// if theres a post submit.if ($_POST(['submit'] ) ) {$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'");$Results = mysql_num_rows($Query);// if user exists goto base.phpif ($Results == '1') {session_register('email');session_register('name');session_rgister('password')header ("Location: base.php");}else{header ("Location: wronglogin.php");}}?>[/code]base.php[code]//if session exists.<?php session_start();if ( (! $_SESSION['username'] )&& (! $_SESSION['password'])) {?>//select with while loop.<?php$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['username']."' and password='".$_SESSION['password']."' ";$st=mysql_query($query);while($row=mysql_fetch_assoc($st)){?><table width="100%"><tr><td width="50%" valign="top" style="padding-right: 25px;"><table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0"><tr><th colspan="2" align="center">User Info</th></tr><tr><td><b>Name</b></td><td><? echo $row['username']; ?></td></tr></table></td></tr></table><?}?><?php//if not logged in goto correct page.}else{header("location: mustlogin.php ");}?> [/code]edited ok Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46767 Share on other sites More sharing options...
klaroen Posted June 17, 2006 Author Share Posted June 17, 2006 not totally :pin login your 3th session register is spelled wrong :p :Dphhh, f** it still not working!! Why not!!Well, let's try again:____________________________________________menu.php (the login form)---------------------------------[code]<form action="login.php" method="post"><table align="center" class="small" style="padding: 0px 0px 5px 0px;" width="130"> <tr> <td align="center"><font color="black">Username:</font></td> </tr> <tr> <td align="center"><input class="login_input" type="text" name="LoginNaam" value=""></td> </tr> <tr> <td align="center"><font color="black">Email:</font></td> </tr> <tr> <td align="center"><input class="login_input" type="text" name="LoginMail" value=""></td> </tr> <tr> <td align="center"><font color="black">Password:</font></td> </tr> <tr> <td align="center"><input class="login_input" type="password" name="LoginPassword"></td> </tr> <tr> <td align="center" style="padding-top: 5px;"><input type="hidden" name="Submit" value="1"><input class="login_input" type="submit" value="Login" style="width: 50px;"></td> </tr></table></form>[/code]--------------------------------------------------------------------------login.php--------------[code]<?php session_start();// connect to database.$DBHost = "localhost";$DBLogin = "klaroen_data";$DBPassword = "******";$DBDatabase = "klaroen_data";mysql_connect("$DBHost", "$DBLogin", "$DBPassword");@mysql_select_db("$DBDatabase");// if theres a post submit.if ($_POST(['Submit'] ) {$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'");$Results = mysql_num_rows($Query);// if user exists goto base.phpif ($Results == '1') {session_register('email');session_register('name');session_register('password');header ("Location: base.php");}else{header ("Location: wronglogin.php");}}?>[/code]------------------------------------------------------base.php-------------[code]<?php session_start();if ((! $_SESSION['username'] )&& (! $_SESSION['password'])) {?><!-- *************** --><!-- Check the login --><!-- And else... --><!-- *************** --><?phpinclude("connect.php");?><?php$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['username']."' and password='".$_SESSION['password']."' ";$st=mysql_query($query);while($row=mysql_fetch_assoc($st)){?> <table width="100%"> <tr> <td width="50%" valign="top" style="padding-right: 25px;"> <table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0"> <tr> <th colspan="2" align="center">User Info</th> </tr> <tr> <td><b>Name</b> </td> <td><? echo $row['username']; ?></td> </tr></table></td></tr></table><? } ?><?php//if not logged in goto correct page.}else{header("location: mustlogin.php ");}?> [/code]-------------------------------------If we can't solve this in the next 30 min, I think I'll quite for this evening (22:26 here)Fingers Crosses! :pklaroen Link to comment https://forums.phpfreaks.com/topic/12250-sessies-not-allowed-or-something/#findComment-46769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.