alex_e Posted September 23, 2009 Share Posted September 23, 2009 Right, hi all first post here, be nice okay, what i want to do is show the username field when a particular person has logged in. heres my code <?php // Connects to your Database mysql_connect("localhost", "username", "pword") or die(mysql_error()); mysql_select_db("username") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { //logged in details at end of page } } } else //if the cookie does not exist, they are taken to the login screen { header("Location: 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=utf-8" /> <title>Instant-Traffic.info - The Worlds Best Traffic Exchange Site</title> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"> <div id="logo"> <h1><a href="index.php">Instant-Traffic.info</a></h1> </div> <!-- end #logo --> <div id="menu"> <ul> <li class="active"><a href="index.php">Home</a></li> <li><a href="members.php">Control Panel</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div> <!-- end #menu --> </div> <!-- end #header --> <div id="page"> <div id="content"> <div style="margin-bottom: 10px;"></div> <div class="post"> <h1 class="title">Thanks For Logging In</h1> <div class="entry"> <p><strong>Thanks for logging in <?php echo $username['username'] ?> </strong></p> <p><strong>For now, this a temporary page whilst the autosurf pages and control panel is made, please be patient during this process. Thank you for co-operation.</strong></p> </div> <div class="meta"></div> </div> </div> <!-- end #content --> <div id="sidebar"> <div id="sidebar-bgtop"></div> <div id="sidebar-content"> <div id="sidebar-bgbtm"> <ul> <li id="search"> <h2>Links</h2> <form method="get" action=""> <fieldset> </fieldset> </form> <ul> <li></li> </ul> </li> <li> <ul> <li></li> <li></li> </ul> </li> </ul> </div> </div> </div> <!-- end #sidebar --> <div style="clear:both; margin:0;"></div> </div> <!-- end #page --> </div> <div id="footer"> <p>© 2008. All Rights Reserved.</p> </div> <!-- end #footer --> </body> </html> obvs the username and pword is filled out in the actual code. the problem is, it only shows the first letter of the username. Link to comment https://forums.phpfreaks.com/topic/175236-showing-username-from-mysql-database/ Share on other sites More sharing options...
dlebowski Posted September 23, 2009 Share Posted September 23, 2009 Do you need the semicolon after ['username']? Before: <p><strong>Thanks for logging in <?php echo $username['username'] ?> After: <p><strong>Thanks for logging in <?php echo $username['username']; ?> Link to comment https://forums.phpfreaks.com/topic/175236-showing-username-from-mysql-database/#findComment-923599 Share on other sites More sharing options...
alex_e Posted September 23, 2009 Author Share Posted September 23, 2009 It doesnt make a difference, either way, only the first letter of the "username" shows Link to comment https://forums.phpfreaks.com/topic/175236-showing-username-from-mysql-database/#findComment-923603 Share on other sites More sharing options...
PFMaBiSmAd Posted September 23, 2009 Share Posted September 23, 2009 You need to use the variable that you fetched from the table - $info['username'] or the variable you set from the $_COOKIE - $username Link to comment https://forums.phpfreaks.com/topic/175236-showing-username-from-mysql-database/#findComment-923605 Share on other sites More sharing options...
alex_e Posted September 23, 2009 Author Share Posted September 23, 2009 ive tried $info['username'] first but it didnt work. as for the second part i tried $_COOKIE['username'] but it didnt work either.... also how can i mod this to redirect to URL listed a file name htp? $redirect="http://www.eg.net"; if(preg_match(array('/Firefox/','/Safari/'),$_SERVER['HTTP_USER_AGENT']))!=1) header("Location: ".$redirect); Link to comment https://forums.phpfreaks.com/topic/175236-showing-username-from-mysql-database/#findComment-923610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.