Jump to content

Recording members who view profile


graham23s

Recommended Posts

Hi Guys,

 

i have this script, it's suppose to record members who view your profile and store it, into the database only i'm getting 2 errors:

 

Warning: explode() [function.explode]: Empty delimiter
Warning: Invalid argument supplied for foreach() 

 

the code:

 

if($member["id"] <> $profile["id"])
{
if(!preg_match("/".$member["id"]."/", $profile["lastvisitors"]))
{
// Update to add new member ID

$lines = explode($profile["lastvisitors"], "\n");
$done = false;

$new = "";

foreach($lines as $line)
{
if($done == false)
{
$done = true;
continue;
}

$new .= $line."\n";
}
}
}

// Removed the first row, now add this user's ID

$new .= $member["id"];

mysql_query("UPDATE `membership` SET `lastvisitors`='$new' WHERE `id`='{$profile['id']}';") or die(mysql_error());

 

i don't know what the problem is any help would be great

 

Graham

Link to comment
Share on other sites

Hi Mate,

 

thanks for that the errors are now gone, this is the last part of the code:

 

if($profile["lastvisitors"] <> "")
{
$last = explode($profile["lastvisitors"], "\n");

foreach($last as $id)
{
$viewer_query = mysql_query("SELECT * FROM `membership` WHERE `id`='$id';") or die(mysql_error());
$viewer = mysql_fetch_array($viewer_query);

echo $viewer["name"]."<br />";
}
}	

 

this is suppose to echo out the name of the user/s who have visited your profile but i's blank nothing echoes out (even when i edit the database to put a name in) is there anything wrong here can you see at all mate?

 

cheers

 

Graham

 

 

Link to comment
Share on other sites

<?php

if($profile["lastvisitors"] != "") {

$last = explode($profile["lastvisitors"], "\n");

foreach($last as $id) {

  $viewer_query = mysql_query("SELECT * FROM membership WHERE id = '$id'") or die(mysql_error());
  $viewer = mysql_fetch_array($viewer_query);
  echo $viewer["name"]."<br />";

}

}

?>

 

Try that.

Link to comment
Share on other sites

Hi Mate,

 

thanks for the help there, it doesn't seem to be working, it neither inserts into the database or echo out a name (when i manually put 1 in) is there any type of troubleshooting i could do?

 

cheers mate

 

Graham

Link to comment
Share on other sites

<?php

if($profile["lastvisitors"] != "") {

$last = explode($profile["lastvisitors"], "\n");

foreach($last as $id) {

  $viewer_query = mysql_query("SELECT * FROM membership WHERE id = '$id'") or die(mysql_error());
  $viewer = mysql_fetch_array($viewer_query) or die(mysql_error());
  echo $viewer["name"]."<br />";

}

} else {

  echo "Query not run!";

}
?>

 

That has debugging :)

Link to comment
Share on other sites

Well basically that means that none of the code in your first if statement (i.e. the query) isn't running because

if($profile["lastvisitors"] != "") is reutning false. Just before your if statement put this:

 

echo "<pre>";
print_r($profile);
echo "</pre>";

 

And let me know the output.

Link to comment
Share on other sites

Hi Mate,

 

the thing is i got the script from another site i didn't fully understand it but i was thinking that my self, i don't know if this is any help but heres the full code to my profile page:

 

<?php
     // For register_global on PHP settings//////////////////////////////////////////////
     $member = $_COOKIE['member'];

     session_start(); // you must put this to read session variables/////////////////////

     if (empty($member) || !isset($member)) // fail to read the browser cookie///////////
     {
     // Try to read session...///////////////////////////////////////////////////////////
     if (empty($_SESSION['member']) || !isset($_SESSION['member']))
     {
           header("Location: login.php"); // redirect user to login//////////////////////
           exit;
     } else {
          $member = $_SESSION['member'];
  }
}
         //Includes... //////////////////////////////////////////////////////////////////
         include("includes/db_connection.php");
         include("includes/constants.php");
         include("includes/header.php");
         include("includes/loginnav.php");
         
         // Remember the users name...///////////////////////////////////////////////////
         $member = $_COOKIE['member']; 
         
         // Get the link info from the view_member_profiles.php /////////////////////////
         if(isset($_GET['id'])) { // this tells the page which id displayed e.g. view_members.php?id=1

         $id = $_GET['id'];
         
         ################################################################################
if($member["id"] <> $profile["id"])
{
if(!preg_match("/".$member["id"]."/", $profile["lastvisitors"]))
{
// Update to add new member ID

$lines = explode("\n", $profile["lastvisitors"]);
$done = false;

$new = "";

foreach($lines as $line)
{
if($done == false)
{
$done = true;
continue;
}

$new .= $line."\n";
}
}
}


// Removed the first row, now add this user's ID

$new .= $member["id"];

mysql_query("UPDATE `membership` SET `lastvisitors`='$new' WHERE `id`='{$profile['id']}';") or die(mysql_error());



      ################################################################################
if($profile["lastvisitors"] != "") {

$last = explode($profile["lastvisitors"], "\n");

foreach($last as $id) {

  $viewer_query = mysql_query("SELECT * FROM membership WHERE id = '$id'") or die(mysql_error());
  $viewer = mysql_fetch_array($viewer_query) or die(mysql_error());
  echo $viewer["name"]."<br />";

}

} else {

  echo "Query not run!";

}
echo "<pre>";
print_r($profile);
echo "</pre>";
      ################################################################################
         
         // this selects the info for that user from the db
         $member = mysql_query("SELECT * FROM membership where id = '$id'"); 
         $row = mysql_fetch_array($member) or die (mysql_error()); 
         
         // Age calculations...//////////////////////////////////////////////////////////
         $birthday = $row["birthday"]; 
         $birthmonth = $row["birthmonth"];
         $birthday = $row["birthyear"]; 
         $dobtimestamp = strtotime($birthday.$birthmonth.date('Y'));
         if($dobtimestamp < time()) {  //Birthday has not been reached.
         
          $age = (date('Y') - $birthday) -1;
          
         } else { //Birthday has been reached
         
          $age = date('Y') - $birthday;
          
         }
         
         // Make a query to see if the user has a 2nd photo...///////////////////////////
         $query_photo_2 = "SELECT photo2 FROM `membership` WHERE username='$member'";
         $result_photo_2 = mysql_query($query_photo_2);
         
         $photo_2 = $row['photo2'];
         
         // When the profile is viewed increment the database.../////////////////////////
         $sql_update = "UPDATE membership SET profile_views = profile_views+1 WHERE id='$id'"; 
         $result_update = mysql_query($sql_update);
         
         $profile_views = $row["profile_views"];
         
         // Make the date more readable...///////////////////////////////////////////////
         $date_format = $row["login"]; 
         $display_date = date("F j, Y, H:i a", strtotime($date_format));
         
         ################################################################################
         @$query_online = "SELECT name FROM useronline WHERE name ='$member'"; 
	  @$user_online = mysql_query($query_online);  
         ################################################################################
         
         // Define the variable for photo1...////////////////////////////////////////////
         $username = $row['username'];
         $marstatus = $row['marstatus'];
         $children = $row['children'];
         $height = $row['height'];
         $weight = $row['weight'];
         $hair = $row['hair'];
         $eye = $row['eye'];
         $smoking = $row['smoking'];
         $drinking = $row['drinking'];
         $hair = $row['hair'];
         $eye = $row['eye'];
         $birthyear = $row['birthyear'];
         $ethnicity = $row['ethnicity'];
         $sexuality = $row['sexuality'];
         $ethnicity = $row['ethnicity'];
         $country = $row['country'];
         $state = $row['state'];
         $iam2 = $row['iam2'];
         $rel_type = $row['rel_type'];
         $photo1 = $row["photo1"];
         $joindate = $row["join_date"];
         $login = $row["login"];
         $headline = $row['headline'];
         $description = $row['description'];
         $lookingfor = $row['lookingfor'];
         $occupation = $row['occupation'];
         $zodiac = $row['zodiac'];
         $avg_votes = $row['avg_votes'];
         $no_of_votes = $row['no_of_votes'];
         
         
         // NEW profile layout may 7th 2007...///////////////////////////////////////////
         echo "<br />
               <table width=\"80%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"5\">
               <tr>
               <td colspan=\"2\" bgcolor=\"#FAAFBE\"><font color=\"#000000\"><b><p>$username</p></b></font></td>
               </tr>
               <tr>
               <td align=\"center\" bgcolor=\"#E2E2E2\">";
         if(empty($photo1)) {         
          echo "<img src='images/no_pic.jpg' />";           
         } else {            
          echo "<img src='members/$photo1' border='0' />"; 
         }                  
         echo "</td>
               </tr>
               </table>";        
               
         // end the first table...///////////////////////////////////////////////////////
         echo "<table width=\"80%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Age:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$age Years Old</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Marital Status:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$marstatus</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>I Am Looking For A:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$iam2</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>For:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$rel_type</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Children:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$children</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Height:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$height</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Weight:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$weight</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Hair Color:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$hair</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Eye Color:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$eye</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Smoking Habits:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$smoking</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Drinking Habits:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$drinking</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Year Born:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$birthyear</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Zodiac Sign:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$zodiac</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Ethnicity:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$ethnicity</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Sexuality:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$sexuality</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Country:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$country</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>State:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$state</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Joined On:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$joindate</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Last Logged In:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p>$display_date</p></td>
               </tr>
               <tr>
               <td width=\"40%\" align=\"right\" bgcolor=\"#F8F7F1\"><p>Profile Views:</p></td><td bgcolor=\"#FAAFBE\" width=\"40%\ align=\"left\"><p><b>$profile_views</b></p></td>
               </tr>"; 
               
              echo "
               <tr>
               <td colspan=\"2\" bgcolor=\"#FAAFBE\"><font color=\"#000000\"><p>Headline</p></font></td>
               </tr>
               <table width=\"80%\" border=\"1\" bordercolor=\"1\" cellspacing=\"0\" cellpadding=\"5\">    
               <tr>
               <td align=\"center\" bgcolor=\"#F8F7F1\"><p>$headline</td>";
              echo "
               </tr>
               <tr>
               <td colspan=\"2\" bgcolor=\"#FAAFBE\"><font color=\"#000000\"><p>Occupation</p></font></td>
               </tr>
               <tr>
               <td align=\"center\" bgcolor=\"#F8F7F1\"><p>$occupation</td>";
              echo "
               </tr>
               <table width=\"80%\" border=\"1\" bordercolor=\"1\" cellspacing=\"0\" cellpadding=\"5\">
               <tr>
               <td colspan=\"2\" bgcolor=\"#FAAFBE\"><font color=\"#000000\"><p>Description</p></font></td>
               </tr>
               <tr>
               <td align=\"center\" bgcolor=\"#F8F7F1\"><p>$description</td>";
              echo "
               <table width=\"80%\" border=\"1\" bordercolor=\"1\" cellspacing=\"0\" cellpadding=\"5\">
               <tr>
               <td colspan=\"2\" bgcolor=\"#FAAFBE\"><font color=\"#000000\"><p>My Ideal Partner</p></font></td>
               </tr>
               <tr>
               <td align=\"center\" bgcolor=\"#F8F7F1\"><p>$lookingfor</td>
               </table>";               
         
         echo "<table width=\"80%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
               <tr>
               <td colspan=\"2\" bgcolor=\"#FAAFBE\"><p>Options</p></td>
               </tr>
               <tr>
               <td width=\"40%\"><a href=\"message_user.php?id=$id\"><img src=\"images/msg_1.gif\" border=\"0\"> Send A Private Message</a></td bgcolor=\"#E2E2E2\"><td width=\"40%\" ><a href=\"report_user.php?id=$id\"><img src=\"images/member_icon.jpg\" border=\"0\"> Report This User</a></td>
               </tr>
               <tr>
               <td width=\"40%\"><a href=\"email_user.php?id=$id\"><img src=\"images/msg_1.gif\" border=\"0\"> E-Mail User</a></td><td><a href=\"view_pics.php?id=$id\">Has More Photos?</a>";
               if(empty($photo_2)) {
         
                echo " (<font color=\"red\"><b>No</b></font>)";
         
                } else {
         
                echo " (<font color=\"green\"><b>Yes</b></font>)";
         
                }   
         echo "</td>
               <tr>
               <td width=\"40%\" bgcolor=\"#FAAFBE\"><p>Rate This User:
               <form action=\"rate.php?id=$id\" method=\"POST\"> 
               <select name=\"rating\"> 
               <option value=\"1\">1</option> 
               <option value=\"2\">2</option> 
               <option value=\"3\">3</option> 
               <option value=\"4\">4</option> 
               <option value=\"5\">5</option>  
               <option value=\"6\">6</option> 
               <option value=\"7\">7</option> 
               <option value=\"8\">8</option> 
               <option value=\"9\">9</option> 
               <option value=\"10\">10</option> 
               </select> 
               <input type=\"submit\" value=\"Rate $username\">
               </form> 
               </td>
               <td bgcolor=\"#FAAFBE\"><p>Average Rating <h1>$avg_votes</h1><p>Profile Rated ($no_of_votes) Times.</td>
               </tr>
               </table>";               
         echo "<br />
               <hr />";
?>		
<?php
}
	$id = mysql_real_escape_string(trim($_GET['id'])); 
	if (empty($id)) {

	 echo "<br /><p>Sorry Invaid ID Or You Aren't Logged In!</p>";
	 echo "<meta http-equiv=\"refresh\" content=\"3;URL=login.php\">";	

	} 


	// Get Profile...//////////////////////////////////////////////////////////////// 
	$query = "SELECT * FROM `membership` where `id`='$id' limit 1"; 
	$result = mysql_query($query) or die(mysql_error()); 

	if (mysql_num_rows($result)==1) {

	$row = mysql_fetch_array($result); 

	$members_email = $row['email'];

	extract($row); 


	// Check Comments...///////////////////////////////////////////////////////////// 
	$query2 = mysql_query("SELECT * FROM `member_comments` WHERE `mid`='$id'") or die(mysql_error()); 		
	$id2 = $id; 		
	$count_comments = mysql_num_rows($query2); 

	$form = '<br /><hr /><br />
	         <table width="60%" border="1" bordercolor="black" cellpadding="2" cellspacing="0">
	         <form action="comment_post.php" method="POST">
	         <tr>
	         <td bgcolor="#E2E2E2"><p>Add A Comment To This Users Profile Below:</td>
	         <tr>
	         <td bgcolor="#E2E2E2"><textarea name="comments" cols="25" rows="10"></textarea></td>	         	         
	         <tr>
	         <td bgcolor="#E2E2E2"><input type="hidden" name="mid" value="'.$id2.'">
	         <input type="submit" value="Add A Comment">
	         </td>
	         </table>
	         </form>'; 
	         
	if ($count_comments != 1) { 

           echo "<p>No Comments Posted Yet On $username's Blog.<br />"; 
        
        } else { 
        
        }
        
        while ($row2=mysql_fetch_array($query2)) { 

        $id2_com = $row2[id]; 
        $quick_name = mysql_query("SELECT * FROM `membership` WHERE `id`='$row2[uid]' LIMIT 1") or die (mysql_error()); 

        while ($n=mysql_fetch_array($quick_name)){ 
        
        $mem_name = $n["username"]; 
        $photo1 = $n["photo1"];
        
        } 
        
        echo '<br /><table width="80%" bordercolor="black" border="1" cellspacing="0" cellpadding="2">
              <tr>
              <td bgcolor="#E2E2E2" width="10%"><img src="members/'.$photo1.'" width="50" height="50"/></td><td bgcolor="#E2E2E2" width="50%"><p>(<a href="profile.php?id='.$row2[uid].'">'.$mem_name.'</a>) On ('.$row2[posted].')</td>
              <tr>
              <td bgcolor="#E2E2E2" width="10%"><p>Comments:</td><td rowspan="2" bgcolor="#FAF8CC" width="50%"><p>'.$row2[comments].'</td>
              <tr rowspan="2">
              <td bgcolor="#E2E2E2" width="10%"><p>Post ID: '.$row2[id].'</td>
              </tr>
              </table>';                  
        } 
                 
        echo $form; 
        
        }     
?>   
<?php
     include("includes/google_ads.php");
     // Include the footer...
     include("includes/footer.php")
?>

 

if you don't see anything wrong mate that's cool i'll take the code out , i'm getting therew ith PHP but not that advanced yet lol

 

cheers mate

 

Graham

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.