jon4433 Posted February 26, 2012 Share Posted February 26, 2012 So I have an simple account centre up, and i'm wanting to display their 'Name' 'Username' and 'Email' as part of their details. But I have one problem... My code doesn't seem to be getting the data from my database... It may be messy to some people, just warning you! <?php session_start(); if($_SESSION['username']){ $connect = mysql_connect("****","****","****") or die("Could not connect to database."); mysql_select_db("****") or die ("Could not find database!"); $sql = mysql_query("SELECT * FROM login"); $username = $rows['username']; $email = $rows['email']; $rows = mysql_fetch_assoc($sql); echo "<p>"; } else header("location: suggestion.html"); ?> <!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="css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { background-color: #CCC; } body,td,th { color: #000; font-family: "MS Serif", "New York", serif; } </style> </head> <body> <div id="wrap"> <!--Header--> <div id="header_member"> </div> <!--Log out and time--> <div id="info"> <div id="date"><script type="text/javascript"> var currentDate = new Date() var day = currentDate.getDate() var month = currentDate.getMonth() + 1 var year = currentDate.getFullYear() document.write("<b>" + day + "/" + month + "/" + year + "</b>") var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes()</script> </div> <div id="time"><script type="text/javascript"> var suffix = "AM"; if (hours >= 12) { suffix = "PM"; hours = hours - 12; } if (hours == 0) { hours = 12; } if (minutes < 10) minutes = "0" + minutes document.write("<b>" + hours + ":" + minutes + " " + suffix + "</b>")</script> </div> </div> <div id="logout"><center><?php echo "<a href='logout.php'>Log out.</a>";?></center></div> <!--Main section which will contain everything else--> <div id="member_main"> <div id="member_right"><center> <p><img src="images/accountinf.png" width="175" height="30" /></p> <p>Name: <?php echo $username;?></p> <p>Email: <?php echo $email;?></p> </center> </div> <div id="member_top"><center><?php echo "Welcome, ".$_SESSION['username'];?></center></div> <div id="member_left" align="center"><img src="images/navigation.png" width="105" height="30" /><img src="images/home_member.png" width="105" height="30" /><img src="images/account.png" width="105" height="30" /></div> </div> <!--Footer--> <div id="footer_member"></div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/257833-displaying-data-from-the-database/ Share on other sites More sharing options...
litebearer Posted February 26, 2012 Share Posted February 26, 2012 just a few things (didn't peruse whole script).. 1. $sql = mysql_query("SELECT * FROM login"); DOESN'T identify which record you really want. Perhaps you need a WHERE clause. 2. this... $rows = mysql_fetch_assoc($sql); A) needs to go right after $sql = mysql_query("SELECT * FROM login"); B) only gets one record from the table; BUT you need to make sure its the right record (see #1) 3. Unless you NEED all the fields from a record, do not use the * in your query, instead list the fields you need. 4. For debugging, it helps if you put your query in a string, that way you can echo the query to ascertain it contains what you expect. Link to comment https://forums.phpfreaks.com/topic/257833-displaying-data-from-the-database/#findComment-1321496 Share on other sites More sharing options...
jon4433 Posted February 26, 2012 Author Share Posted February 26, 2012 You are a life saver! I've been stumpt for the past few hours, I'll be testing what you said very soon. Thank you for the help Link to comment https://forums.phpfreaks.com/topic/257833-displaying-data-from-the-database/#findComment-1321507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.