i get this error message....
Notice: Undefined index: comments in /home/content/50/8811650/html/member1.php on line 305
Warning: Invalid argument supplied for foreach() in /home/content/50/8811650/html/member1.php on line 305
it adds a comment to the database, however it doesn't show on the users page??
member page
<?php
error_reporting(E_ALL);
include ("coreblog/initblog.php");
include('core/init.inc.php');
$user_info = fetch_user_info($_GET['uid']);
if (isset($_GET['uid'], $_POST['user'], $_POST['body'])){
if (add_wall_comment($_GET['uid'], $_POST['user'], $_POST['body'])){
header("Location: member1.php?uid={$_GET['uid']}");
}else{
header('Location: member1.php');
}
die();
}
?>
<!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><?php echo $user_info['username']; ?>'s Portfolio - Know Quest</title>
<style type="text/css">
<!--
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
background: #42413C;
margin: 0;
padding: 0;
color: #000;
background-color: #FFFFFF;
}
/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
padding: 0;
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
margin-top: 0; /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
padding-right: 15px;
padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
text-align: left;
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
border: none;
}
/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
color: #C4B43C;
text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
color: #C4B43C;
text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
text-decoration: none;
}
/* ~~this fixed width container surrounds the other divs~~ */
.container {
width: 1200px;
background: #FFF;
margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
}
/* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
.header {
background: #1D3164;
width: 1200px;
}
/* ~~ These are the columns for the layout. ~~
1) Padding is only placed on the top and/or bottom of the divs. The elements within these divs have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.
2) No margin has been given to the columns since they are all floated. If you must add margin, avoid placing it on the side you're floating toward (for example: a right margin on a div set to float right). Many times, padding can be used instead. For divs where this rule must be broken, you should add a "display:inline" declaration to the div's rule to tame a bug where some versions of Internet Explorer double the margin.
3) Since classes can be used multiple times in a document (and an element can also have multiple classes applied), the columns have been assigned class names instead of IDs. For example, two sidebar divs could be stacked if necessary. These can very easily be changed to IDs if that's your preference, as long as you'll only be using them once per document.
4) If you prefer your nav on the right instead of the left, simply float these columns the opposite direction (all right instead of all left) and they'll render in reverse order. There's no need to move the divs around in the HTML source.
*/
.sidebar1 {
float: left;
width: 195px;
background: white;
padding-bottom: 10px;
border-right-width: thin;
border-bottom-color: #000;
}
.content {
padding: 10px 0;
width: 1000px;
float: left;
}
/* ~~ This grouped selector gives the lists in the .content area space ~~ */
.content ul, .content ol {
padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */
}
/* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */
ul.nav {
list-style: none; /* this removes the list marker */
border-top: 1px solid #666; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
margin-bottom: 15px; /* this creates the space between the navigation on the content below */
}
ul.nav li {
border-bottom: 1px solid #666; /* this creates the button separation */
}
ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
padding: 5px 5px 5px 15px;
display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
width: 160px; /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */
text-decoration: none;
background: #C6D580;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
background: #ADB96E;
color: #FFF;
}
/* ~~ The footer ~~ */
.footer {
padding: 10px 0;
background: #1D3164;
position: relative;/* this gives IE6 hasLayout to properly clear */
clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
}
/* ~~ miscellaneous float/clear classes ~~ */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
h5 {
color: #FFF;
font-size: 10pt;
}
h6 {
color: #090;
}
h4 {
font-size: 11pt;
color: #000;
}
h3 {
font-size: 11pt;
}
h2 {
font-size: 12pt;
}
body,td,th {
font-size: 10pt;
}
.container .content form h3 label {
text-align: center;
}
.container .content form h3 label {
text-align: center;
}
.container .content form h3 label {
text-align: center;
}
-->
</style></head>
<body>
<div class="container">
<div class="header"><!-- end .header -->
<p> </p>
<p><img src="Images/Untitled-1.jpg" alt="Logo Web Header" width="537" height="92" align="left" /></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<h5><b><?php echo $_SESSION['username']; ?></b> <?php echo "<a href='logout.php'>Logout</a>";?> |<a href="Edit.php"> <?php echo "<a href='member1.php?uid={$_SESSION['uid']}'>Your Research</a>"; ?></a> | <a href="Edit.php">Edit Portfolio</a> |<a href="protected.php"> To Do List</a> | <a href="blog_posts.php">Post Research</a> | <a href="search_posts.php">Viral Search</a> </a>| <a href="prof_finder.php">Prof. Finder </a>| <a href="user_lists.php">User List</a> |<a href="all research.php"> Colaborated Research</a></h5>
</div>
<div class="sidebar1">
<p> </p>
<p> </p>
<h3><a href="blog_list.php"><?php echo $_SESSION['username'];?> Research</a></h3>
<h4>
<?php
$posts = get_posts();
foreach ($posts as $post){
?>
<h2><a href="blog_read.php?pid=<?php echo $post['id']; ?>"> <?php echo $post['title']; ?></a></h2>
<h4>By <?php echo $post['user']; ?> on <?php echo $post['date']; ?></h4>
<h4>(<?php echo $post['total_comments'];?> comments, last comment <?php echo $post['last_comment']; ?>)</h4>
<hr />
<p><?php $post['preview']; ?></p>
<?php
}
?>
</h4>
<p> </p>
<p> </p>
<p> </p>
<!-- end .sidebar1 --></div>
<div class="content">
<p> </p>
<table width="93%" cellpadding="10" cellspacing="10">
<tr>
<td width="22%" height="172"><h4><strong>Country</strong></h4>
<p><?php echo $user_info['location']; ?></p>
<td width="22%"><h4><strong>Institution</strong></h4>
<p><?php echo $user_info['institution']; ?></p></td>
<td width="23%"><h4><strong>Articles Published (Reffered)</strong></h4>
<p><?php echo $user_info['articlespublishedpre']; ?></p></td>
</tr>
<tr>
<td height="151"><h4><strong>Websit</strong><strong>e</strong></h4>
<p><?php echo $user_info['website']; ?></p></td>
<td><h4><strong>
<label for='professionalresearch5'>Research Center</label>
</strong></h4>
<p><?php echo $user_info['researchcentre']; ?></p></td>
<td><h4><strong>Articles Published (Non-Reffered)</strong></h4>
<p><?php echo $user_info['researchcentre']; ?></p>
<h4> </h4></td>
</tr>
<tr>
<td height="154"><h4><strong>Email</strong></h4>
<p><?php echo $user_info['researchcentre']; ?></p></td>
<td><h4><strong>Department</strong></h4>
<p><?php echo $user_info['department']; ?></p></td>
<td><h4><strong>Published Books</strong></h4>
<p><?php echo $user_info['publishedbooks']; ?></p></td>
</tr>
<tr>
<td><h4><strong>Social Networking</strong></h4>
<p><?php echo $user_info['socialmedia']; ?></p> </p></td>
<td><h4><img src="<?php echo $user_info['avatar']; ?>" alt="Avatar"/></h4></td>
<td><h4><strong>Published Chapters</strong></h4>
<p><?php echo $user_info['publishedchapters']; ?></p>
<h4> </h4></td>
</tr>
<tr>
<td height="162"><h4><strong>Researchers Cited in Your Research</strong></h4>
<p><?php echo $user_info['researcherscitedinyourresearch']; ?></p></td>
<td><h4><strong>Memberships</strong></h4>
<p><?php echo $user_info['memberships']; ?></p></td>
<td><h4><strong>Research Methodology Perferred</strong></h4>
<p><?php echo $user_info['researchmethodologyperferred']; ?></p></td>
</tr>
<tr>
<td height="144"><h4><strong>Non-acidemic Influences</strong></h4>
<p><?php echo $user_info['nonacidemicinfluences']; ?></p>
<td><h4>Acidemic Influences</h4>
<p><?php echo $user_info['acidemicinfluences']; ?></p></td>
<td><h4><strong>Confidence Proceedings</strong></h4>
<p><?php echo $user_info['confidenceproceedings']; ?></p></td>
</tr>
<tr>
<td height="171"><h4><strong>Speciality</strong></h4>
<p><?php echo $user_info['speciality']; ?></p></td>
<td><h4><strong>Key Words</strong></h4>
<p><?php echo $user_info['keywords']; ?>
</h2>
</p></td>
<td><h4><strong>Data Sets</strong></h4>
<p><?php echo $user_info['datasets']; ?></p></td>
</tr>
</table>
<center>
<p> </p>
<p> </p>
<p> </p>
<hr />
<p> </p>
<?php
if (isset($_GET['uid']) === false || valid_uid($_GET['uid']) === false){
echo 'Invalid username.';
}else{
$post = get_wall_comments($_GET['uid'])
?>
<?php
foreach ($post['comments'] as $comment){
?>
<h3>By: <?php echo $comment['body']; ?> on <?php echo $comment['date']; ?></h3>
<p><?php echo $comment['user']; ?></p>
<hr />
<?php
}
?>
<form action="" method="post">
<p>
<label for="user">Name</label>
<input type="text" name="user" id="user" value="<?php echo $_SESSION['username']; ?>" />
</p>
<p>
<textarea name="body" rows="20" cols="60"></textarea>
</p>
<p>
<input type="submit" value="Add Comment" />
</p>
</form>
<?php
}
?>
<h1> </h1>
<!-- end .content --></div>
<div class="footer">
<form>
<h5>___________________________________________________________________________________________________________________________________</h5>
<h5><a href="termsofuse.html">Terms of use</a><b> </b>|<a href="Edit.php"> <?php echo "<a href='member1.php?uid={$_SESSION['uid']}'>Your Research</a>"; ?></a> | <a href="Edit.php">Edit Portfolio</a> |<a href="protected.php"> To Do List</a> | <a href="blog_posts.php">Post Research</a> | <a href="search_posts.php">Viral Search</a> </a>| <a href="prof_finder.php">Prof. Finder </a>| <a href="user_lists.php">User List</a> |<a href="all research.php"> Colaborated Research</a></h5>
<h5> </h5>
</form>
<h6><center>Powered by: <a href="http://jaysco.ca/">Jaysco</a></center>
<!-- end .footer --></h6>
</div>
<!-- end .container --></div>
</body>
</html>
comments 2
<?php
error_reporting(E_ALL);
//fetches the current logged in users id
function fetch_current_user_id($username){
$username = mysql_real_escape_string($username);
$sql = "SELECT `user_id` FROM `users` WHERE `user_username` = '{$username}'";
$result = mysql_query($sql);
return mysql_result($result, 0);
}
//check if given username exsists in the database
function user_exists($user){
$user = mysql_real_escape_string($user);
$total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_username` = '{$user}'");
echo mysql_error();
return (mysql_result($total, 0) == '1') ? true : false;
}
//check if the given username and password combinations are valid
function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
$total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_username` = '{$user}' AND `user_password` = '{$pass}'");
return (mysql_result($total, 0) == '1') ? true : false;
}
//checks to see is user account is active
function is_active($user){
$user = mysql_real_escape_string($user);
echo mysql_error();
$sql = "SELECT
COUNT(`activations`.`user_id`)
FROM `users`
INNER JOIN `activations`
ON `users`.`user_id` = `activations`.`user_id`
WHERE `users`.`user_username` = '{$user}'";
$result = mysql_query($sql);
echo mysql_error();
return (mysql_result($result, 0) == '0') ? true : false;
}
//acctivates the account related to the given activation code
function activate_account($aid){
$aid = mysql_real_escape_string($aid);
mysql_query("DELETE FROM `activations` WHERE `activation_code` = '{$aid}'");
echo mysql_error();
}
//adds a user to the database
function add_user($user, $email, $pass, $first, $last){
$user = mysql_real_escape_string(htmlentities($user));
$email = mysql_real_escape_string($email);
$pass = sha1($pass);
$first = mysql_real_escape_string(htmlentities($first));
$last = mysql_real_escape_string(htmlentities($last));
$charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9')));
$aid =implode('', array_rand($charset, 10));
$body = <<<EMAIL
Thank you for signing up with knowquest. To activate your account, please click the link below:
http://www.jasonmassieportfolio.com/act ... ?aid={$aid}
EMAIL;
mail($email, 'Your new account at Knowquest.com', $body, 'From: admin@knowquest.com');
mysql_query("INSERT INTO `users` (`user_username`, `user_email`, `user_password`,`user_firstname`,`user_lastname`) VALUES ('{$user}', '{$email}', '{$pass}','{$first}','{$last}')");
echo mysql_error();
$user_id = mysql_insert_id();
mysql_query("INSERT INTO `activations` (`user_id`, `activation_code`) VALUES ({$user_id}, '{$aid}')");
echo mysql_error();
}
//fetches all of the users from the table
function fetch_users(){
$result = mysql_query("SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users`");
$users = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$users[] = $row;
}
return $users;
}
//fetches profile info for given user
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`user_id` AS `id`,
`user_username` AS `username`,
`user_email` AS `email`,
`user_firstname` AS `firstname`,
`user_lastname` AS `lastname`,
`user_institution` AS `institution`,
`user_department` AS `department`,
`user_location` AS `location`,
`user_speciality` AS `speciality`,
`user_key words` AS `keywords`,
`user_research centre` AS `researchcentre`,
`user_website` AS `website`,
`user_articles published pre` AS `articlespublishedpre`,
`user_articles published non pre` AS `articlespublishednonpre`,
`user_published books` AS `publishedbooks`,
`user_social media` AS `socialmedia`,
`user_published chapters` AS `publishedchapters`,
`user_confidence proceedings` AS `confidenceproceedings`,
`user_non acidemic influences` AS `nonacidemicinfluences`,
`user_data sets` AS `datasets`,
`user_research methodology perferred` AS `researchmethodologyperferred`,
`user_researchers cited in your research` AS `researcherscitedinyourresearch`,
`user_memberships` AS `memberships`,
`user_acidemic influences` AS `acidemicinfluences`
FROM `users`
WHERE `user_id` = {$uid}";
$result = mysql_query($sql);
echo mysql_error();
$info = mysql_fetch_assoc($result);
$info['avatar'] = (file_exists("{$GLOBALS['path']}/user_avatars/{$info['id']}.jpg")) ? "core/user_avatars/{$info['id']}.jpg" : "core/user_avatars/default.jpg";
return $info;
}
//updates current user portfolio info
function set_profile_info($email, $institution, $department, $location, $speciality, $keywords, $researchcentre, $website, $articlespublishedpre, $articlespublishednonpre, $publishedbooks, $socialmedia, $publishedchapters, $confidenceproceedings, $nonacidemicinfluences, $datasets, $researchmethodologyperferred, $researcherscitedinyourresearch, $memberships, $acidemicinfluences, $avatar){
$email = mysql_real_escape_string(htmlentities($email));
$institution = mysql_real_escape_string(htmlentities($institution));
$department = mysql_real_escape_string(htmlentities($department));
$location = mysql_real_escape_string(htmlentities($location));
$speciality = mysql_real_escape_string(htmlentities($speciality));
$keywords = mysql_real_escape_string(htmlentities($keywords));
$researchcentre = mysql_real_escape_string(htmlentities($researchcentre));
$website = mysql_real_escape_string(htmlentities($website));
$articlespublishedpre = mysql_real_escape_string(htmlentities($articlespublishedpre));
$articlespublishednonpre = mysql_real_escape_string(htmlentities($articlespublishednonpre));
$publishedbooks = mysql_real_escape_string(htmlentities($publishedbooks));
$socialmedia = mysql_real_escape_string(htmlentities($socialmedia));
$publishedchapters = mysql_real_escape_string(htmlentities($publishedchapters));
$confidenceproceedings = mysql_real_escape_string(htmlentities($confidenceproceedings));
$nonacidemicinfluences = mysql_real_escape_string(htmlentities($nonacidemicinfluences));
$datasets = mysql_real_escape_string(htmlentities($datasets));
$researchmethodologyperferred = mysql_real_escape_string(htmlentities($researchmethodologyperferred));
$researcherscitedinyourresearch = mysql_real_escape_string(htmlentities($researcherscitedinyourresearch));
$memberships = mysql_real_escape_string(htmlentities($memberships));
$acidemicinfluences = mysql_real_escape_string(htmlentities($acidemicinfluences));
if (file_exists($avatar)){
$src_size = getimagesize($avatar);
if ($src_size['mime'] === 'image/jpeg'){
$src_img = imagecreatefromjpeg($avatar);
}else if ($src_size['mime'] === 'image/png'){
$src_img = imagecreatefrompng($avatar);
}else if ($src_size['mime'] === 'image/gif'){
$src_img = imagecreatefromgif($avatar);
}else{
$src_img = false;
}
if ($src_img !== false){
$thumb_width = 200;
if ($src_size[0] <= $thumb_width){
$thumb = $src_img;
}else{
$new_size[0] = $thumb_width;
$new_size[1] = ($src_size[1] / $src_size[0]) * $thumb_width;
$thumb = imagecreatetruecolor($new_size[0], $new_size[1]);
imagecopyresampled($thumb, $src_img, 0, 0, 0, 0, $new_size[0], $new_size[1], $src_size[0], $src_size[1]);
}
imagejpeg($thumb, "{$GLOBALS['path']}/user_avatars/{$_SESSION['uid']}.jpg");
}
}
$sql = "UPDATE `users` SET
`user_email` = '{$email}',
`user_institution` = '{$institution}',
`user_department` = '{$department}',
`user_location` = '{$location}',
`user_speciality` = '{$speciality}',
`user_key words` = '{$keywords}',
`user_research centre` = '{$researchcentre}',
`user_website` = '{$website}',
`user_articles published pre` = '{$articlespublishedpre}',
`user_articles published non pre` = '{$articlespublishednonpre}',
`user_published books` = '{$publishedbooks}',
`user_social media` = '{$socialmedia}',
`user_published chapters` = '{$publishedchapters}',
`user_confidence proceedings` = '{$confidenceproceedings}',
`user_non acidemic influences` = '{$nonacidemicinfluences}',
`user_data sets` = '{$datasets}',
`user_research methodology perferred` = '{$researchmethodologyperferred}',
`user_researchers cited in your research` = '{$researcherscitedinyourresearch}',
`user_memberships` = '{$memberships}',
`user_acidemic influences` = '{$acidemicinfluences}'
WHERE `user_id` = {$_SESSION['uid']}";
mysql_query($sql);
echo mysql_error();
}
//checks if the given user id is in the table
function valid_uid($uid){
$uid = (int)$uid;
$total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_id` = {$uid}");
$total = mysql_result($total, 0);
if ($total != 1){
return false;
}else{
return true;
}
}
//fetches all the comments for a given user wall post
function get_wall_comments($uid){
$uid = (int)$uid;
$sql = "SELECT
`comment_body` AS `body`,
`comment_user` AS `user`,
DATE_FORMAT(`comment_date`, '%d/%m/%Y %H:%i:%s') AS `date`
FROM `wallcomments`
WHERE `user_id` = {$uid}";
$comments = mysql_query($sql);
$return = array();
while (($row = mysql_fetch_assoc($comments)) !== false){
$return[] = $row;
}
return $return;
}
//add a wall comment
function add_wall_comment($uid, $body, $user){
if (valid_uid($uid) === false){
return false;
}
$uid = (int)$uid;
$body = mysql_real_escape_string(nl2br(htmlentities($body)));
$user = mysql_real_escape_string(htmlentities($user));
mysql_query("INSERT INTO `wallcomments` (`user_id`, `comment_body`, `comment_user`, `comment_date`) VALUES ('{$uid}', '{$user}', '{$body}', NOW())");
echo mysql_error();
return true;
}
?>