herghost Posted September 22, 2009 Share Posted September 22, 2009 Hi all, I have this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <link rel="stylesheet" href="images/CoolWater.css" type="text/css" /> <script src="include/ajaxpageload.js" type="text/javascript"></script> <?php include ('include/auth.inc.php'); include ('include/dbconnect.php'); $query = 'SELECT username, first_name, last_name, city, state, email, postcode FROM users u JOIN users_info i ON u.user_id = i.user_id WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $conn) . '"'; $result = mysql_query($query, $conn) or die(mysql_error($conn)); $row = mysql_fetch_array($result); extract($row); mysql_free_result($result); mysql_close($conn); ?> <title>Project</title> </head> <body> <!-- wrap starts here --> <div id="wrap"> <!--header --> <div id="header"> <h1 id="logo-text"><a href="index.html">coolwater</a></h1> <p id="slogan">put your site slogan here...</p> <div id="header-links"> </div> </div> <!-- navigation --> <div id="menu"> <ul> <li><a href="/project/">Home</a></li> <li><a href="javascript:ajaxpage('about.php', 'main');">About</a></li> <li><a href="javascript:ajaxpage('register.php', 'main');">Register</a></li> <li><a href="javascript:ajaxpage('post.php', 'main');">Post Problem</a></li> <li><a href="javascript:ajaxpage('techs.php', 'main');">Find Tech</a></li> <li><a href="javascript:ajaxpage('solutions.php', 'main');">Solution Center</a></li> </ul> </div> <!-- content-wrap starts here --> <div id="content-wrap"> <div id="main"> <h1>Welcome to your personal information area.</h1> <p>Here you can update your personal information, or delete your account.</p> <p>Your information as you currently have it is shown below.</p> <p><a href="main.php">Click here</a> to return to the home page.</p> <ul> <li>First Name: <?php echo $first_name; ?></li> <li>Last Name: <?php echo $last_name; ?></li> <li>City: <?php echo $city; ?></li> <li>State: <?php echo $state; ?></li> <li>Email: <?php echo $email; ?></li> <li>Postcode: <?php echo $postcode; ?></li> <li>Username: <?php echo $username; ?></li> </ul> <p><a href="update_account.php">Update Account</a> | <a href="delete_account.php">Delete Account</a></p> </div> <div id="sidebar"> <?php if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) { ?> <p>Welcome Back, <b><?php echo $_SESSION['username'];?>.</b></p> <?php if ($_SESSION['admin_level'] > 0) { echo '<p><a href="admin_area.php">Click here</a> to access your ' . 'administrator tools.</p>'; } } else { ?> <h2>Member Login</h2> <?php session_start(); include ('include/dbconnect.php'); // filter incoming values $username = (isset($_POST['username'])) ? trim($_POST['username']) : ''; $password = (isset($_POST['password'])) ? $_POST['password'] : ''; $redirect = (isset($_REQUEST['redirect'])) ? $_REQUEST['redirect'] : 'account.php'; if (isset($_POST['submit'])) { $query = 'SELECT admin_level FROM users WHERE ' . 'username = "' . mysql_real_escape_string($username, $conn) . '" AND ' . 'password = PASSWORD("' . mysql_real_escape_string($password, $conn) . '")'; $result = mysql_query($query, $conn) or die(mysql_error($conn)); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $_SESSION['username'] = $username; $_SESSION['logged'] = 1; $_SESSION['admin_level'] = $row['admin_level']; header ('Refresh: 5; URL=' . $redirect); echo '<p>You will be redirected to your original page request.</p>'; echo '<p>If your browser doesn\'t redirect you properly automatically, ' . '<a href="' . $redirect . '">click here</a>.</p>'; mysql_free_result($result); mysql_close($conn); die(); } else { // set these explicitly just to make sure $_SESSION['username'] = ''; $_SESSION['logged'] = 0; $_SESSION['admin_level'] = 0; $error = '<p><strong>You have supplied an invalid username and/or ' . 'password!</strong> Please <a href="register.php">click here ' . 'to register</a> if you have not done so already.</p>'; } mysql_free_result($result); } ?> <?php if (isset($error)) { echo $error; } ?> <form action="login.php" method="post"> Username: <input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>"/></td> Password: <input type="password" name="password" maxlength="20" size="20" value="<?php echo $password; ?>"/></td> <input type="hidden" name="redirect" value="<?php echo $redirect ?>"/> <input type="submit" name="submit" value="Login" class="button"/> </form> <?php mysql_close($conn); ?> <?php } ?> </div> <!-- content-wrap ends here --> </div> <?php include('include/footer.php'); ?> <!-- wrap ends here --> </div> </body> </html> What I want to do is display the field $credits from the table users_credits in the div header-links! I have tried everything and am getting error after error so I thought id see how you would do it on here! Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/175124-solved-display-info-from-database/ Share on other sites More sharing options...
DavidAM Posted September 22, 2009 Share Posted September 22, 2009 Stick a loop in there. Something like this ... <div id="header-links"> <?php $queryC = 'SELECT credits FROM user_credits WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $conn) . '"'; $resultC = mysql_query($query, $conn) or die(mysql_error($conn)); foreach ($rowC = mysql_fetch_assoc($resultC)) { echo $rowC['credits'] . '<BR>'; // with appropriate formatting } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/175124-solved-display-info-from-database/#findComment-923020 Share on other sites More sharing options...
herghost Posted September 23, 2009 Author Share Posted September 23, 2009 I am getting a parse error on line 53: 52. $resultC = mysql_query($query, $conn) or die(mysql_error($conn)); 53. foreach ($rowC = mysql_fetch_assoc($resultC)) { 54. 55. echo "<li code] Quote Link to comment https://forums.phpfreaks.com/topic/175124-solved-display-info-from-database/#findComment-923288 Share on other sites More sharing options...
Zane Posted September 23, 2009 Share Posted September 23, 2009 because it's while ($rowC = mysql_fetch_assoc($resultC)) { not foreach ($rowC = mysql_fetch_assoc($resultC)) { Quote Link to comment https://forums.phpfreaks.com/topic/175124-solved-display-info-from-database/#findComment-923294 Share on other sites More sharing options...
herghost Posted September 23, 2009 Author Share Posted September 23, 2009 Thanks zanus, however I am now getting the following: Warning: mysql_real_escape_string(): 5 is not a valid MySQL-Link resource in C:\wamp\www\project\account.php on line 51 Warning: mysql_query(): 5 is not a valid MySQL-Link resource in C:\wamp\www\project\account.php on line 52 Warning: mysql_error(): 5 is not a valid MySQL-Link resource in C:\wamp\www\project\account.php on line 52 50. $queryC = 'SELECT credits FROM user_credits WHERE username = "' . 51. mysql_real_escape_string($_SESSION['username'], $conn) . '"'; 52. $resultC = mysql_query($query, $conn) or die(mysql_error($conn)); 53. while ($rowC = mysql_fetch_assoc($resultC)) { Quote Link to comment https://forums.phpfreaks.com/topic/175124-solved-display-info-from-database/#findComment-923300 Share on other sites More sharing options...
herghost Posted September 23, 2009 Author Share Posted September 23, 2009 Sorted! had to remove the connection close earlier in the script Quote Link to comment https://forums.phpfreaks.com/topic/175124-solved-display-info-from-database/#findComment-923319 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.