help with sessions please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

help with sessions please

Post by timoteo »

Hi, I have a problem which has kept me up for a week now. I am new to all this and am creating a page in dreamweaver which has 4 sql tables all with 'userid' as a common denominator. I am trying to create a session variable through a log in page (username and pass) to display the results for that user from the 4 sql tables on a 'profilesummary' page. However I can not register userid and therefore all results from the tables are displayed on the profile summary page - I can't link it to the log in info. Here is the php code from the 'profilesummary' page where I am trying to set the SESSION and it comes out NULL. Can anyone help please!!! I want to sleep!!! I would very much appreciate any help anyone may be able to provide. Thanks in advance.

Code: Select all

<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
session_start();
?><?php
($_SESSION['userid'] = $rsusername.userid);
$query= 'SELECT userid FROM username WHERE username.username = $MM_Username';
$result = mysql_query($query);
echo gettype($array['userid']);?>
<?php echo $_SESSION['userid']; ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$colname_rsusername = "1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsusername = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsusername = sprintf("SELECT * FROM username WHERE username = '%s'", $colname_rsusername);
$rsusername = mysql_query($query_rsusername, $recommendingpeople) or die(mysql_error());
$row_rsusername = mysql_fetch_assoc($rsusername);
$totalRows_rsusername = mysql_num_rows($rsusername);

$colname_rsbusinessdetails = "1";
if (isset($_SESSION['userid'])){
  $colname_rsbusinessdetails = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
  }
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsbusinessdetails = sprintf("SELECT * FROM businessdetails WHERE userid = %s", $colname_rsbusinessdetails);
$rsbusinessdetails = mysql_query($query_rsbusinessdetails, $recommendingpeople) or die(mysql_error());
$row_rsbusinessdetails = mysql_fetch_assoc($rsbusinessdetails);
$totalRows_rsbusinessdetails = mysql_num_rows($rsbusinessdetails);

$colname_rsbusinessdescription = "1";
if (isset($_SESSION['userid'])) {
  $colname_rsbusinessdescription = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsbusinessdescription = sprintf("SELECT * FROM businessdescription WHERE userid = %s", $colname_rsbusinessdescription);
$rsbusinessdescription = mysql_query($query_rsbusinessdescription, $recommendingpeople) or die(mysql_error());
$row_rsbusinessdescription = mysql_fetch_assoc($rsbusinessdescription);
$totalRows_rsbusinessdescription = mysql_num_rows($rsbusinessdescription);

$colname_rsrecommendations = "1";
if (isset($_SESSION['userid'])) {
  $colname_rsrecommendations = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsrecommendations = sprintf("SELECT * FROM recommendations WHERE userid = %s", $colname_rsrecommendations);
$rsrecommendations = mysql_query($query_rsrecommendations, $recommendingpeople) or die(mysql_error());
$row_rsrecommendations = mysql_fetch_assoc($rsrecommendations);
$totalRows_rsrecommendations = mysql_num_rows($rsrecommendations);

$maxRows_rsrecommendations = 10;
$pageNum_rsrecommendations = 0;
if (isset($_GET['pageNum_rsrecommendations'])) {
  $pageNum_rsrecommendations = $_GET['pageNum_rsrecommendations'];
}
$startRow_rsrecommendations = $pageNum_rsrecommendations * $maxRows_rsrecommendations;

$colname_rsrecommendations = "1";
if (isset($_SESSION['userid'])) {
  $colname_rsrecommendations = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsrecommendations = sprintf("SELECT * FROM recommendations WHERE userid = %s", $colname_rsrecommendations);
$query_limit_rsrecommendations = sprintf("%s LIMIT %d, %d", $query_rsrecommendations, $startRow_rsrecommendations, $maxRows_rsrecommendations);
$rsrecommendations = mysql_query($query_limit_rsrecommendations, $recommendingpeople) or die(mysql_error());
$row_rsrecommendations = mysql_fetch_assoc($rsrecommendations);
if (isset($_GET['totalRows_rsrecommendations'])) {
  $totalRows_rsrecommendations = $_GET['totalRows_rsrecommendations'];
} else {
  $all_rsrecommendations = mysql_query($query_rsrecommendations);
  $totalRows_rsrecommendations = mysql_num_rows($all_rsrecommendations);
}
$totalPages_rsrecommendations = ceil($totalRows_rsrecommendations/$maxRows_rsrecommendations)-1;

$queryString_rsrecommendations = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rsrecommendations") == false && 
        stristr($param, "totalRows_rsrecommendations") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rsrecommendations = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rsrecommendations = sprintf("&totalRows_rsrecommendations=%d%s", $totalRows_rsrecommendations, $queryString_rsrecommendations);
?>
<?php $MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
Last edited by Benjamin on Sat Jan 08, 2011 3:01 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: help with sessions please

Post by Neilos »

You code seems to be very jumbled at the beginning (which was as far as I got). Remember that php will execute the code from top to bottom, you seem to be trying to use variables that you have not initialised.

Code: Select all

<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
session_start();
?><?php
($_SESSION['userid'] = $rsusername.userid);
$query= 'SELECT userid FROM username WHERE username.username = $MM_Username';
$result = mysql_query($query);
echo gettype($array['userid']);?>
<?php echo $_SESSION['userid']; ?>
Try this;

Code: Select all

<?php

session_start();

require_once('Connections/recommendingpeople.php');

$MM_Username = "User"; // some string for the username, maybe from a POST variable

$query= "SELECT userid FROM username WHERE username.username = '$MM_Username';";
$result = mysql_query($query);
$accountData = mysql_fetch_array($result, MYSQL_ASSOC);

$userid = $accountData['userid'];

$_SESSION['userid'] = $userid;

echo $_SESSION['userid'];

?>
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: help with sessions please

Post by timoteo »

thankyou for your prompt reply. I tried what you kindly suggested and got the following error on top of the browser and no data displayed:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/biomagn1/public_html/recommendingpeople.com/profilesummary.php on line 10

I appreciate your help.
Thanks
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: help with sessions please

Post by Neilos »

That means that this;

Code: Select all

$result = mysql_query($query);
is not returning any results. The query;

Code: Select all

$query= "SELECT userid FROM username WHERE username.username = '$MM_Username';";
should be checked, I just copied what you had. If the field header is called username then try this, and is the table called username too?;

Code: Select all

<?php

session_start();

require_once('Connections/recommendingpeople.php');

$MM_Username = "User"; // some string for the username, maybe from a POST variable

$query= "SELECT userid FROM username WHERE username='$MM_Username';";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);

if ($numRows == 1) {
	$accountData = mysql_fetch_array($result, MYSQL_ASSOC);

	$userid = $accountData['userid'];

	$_SESSION['userid'] = $userid;

	echo $_SESSION['userid'];

} elseif ($numRows > 1) {
	echo "Lots of rows were returned";
} else {
	echo "No rows were returned";
}

?>
Remember that the query should be in the format of;

Code: Select all

// select the field and/or fields
$query = "SELECT userid ";

//from the table
$query .= "FROM username ";

// where the value is equal to
$query .= "WHERE username='$MM_Username';";

// it returns the selected fields as a row or rows of data
$result = mysql_query($query);
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: help with sessions please

Post by timoteo »

Hi, thanks for the suggestion. I tried it but got:
Parse error: syntax error, unexpected T_STRING in /home/biomagn1/public_html/recommendingpeople.com/profilesummary.php on line 13

Yes username is a table with the columns userid, username, password, first name, last name.
userid is my universal value to get data from the other tables. MM_Username is the SESSION value set in the dreamweaver login script from username and password.
I appreciate your help and suggestions. I am not alone!!!! :)
thankyou
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: help with sessions please

Post by Neilos »

I make line 13 as this line;

Code: Select all

if ($numRows == 1) {
But that doesn't seem right as mysql_num_rows returns an integer. What line is line 13 of your script.

Unless you are getting no rows returned in which case $numRows will equate to false, so try;

Code: Select all

<?php

session_start();

require_once('Connections/recommendingpeople.php');

$MM_Username = "User"; // some string for the username, maybe from a POST variable

$query= "SELECT userid FROM username WHERE username='$MM_Username';";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);

if ($numRows) {

        if ($numRows == 1) {
        $accountData = mysql_fetch_array($result, MYSQL_ASSOC);

                $userid = $accountData['userid'];

                $_SESSION['userid'] = $userid;

                echo $_SESSION['userid'];

        } elseif ($numRows > 1) {
        echo "Lots of rows were returned";
        } else {
        echo "No rows were returned";
        }

} else {

        echo "No rows were returned";

}

?>
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: help with sessions please

Post by timoteo »

still no luck. It is still indicating the same error:
Parse error: syntax error, unexpected T_STRING in /home/biomagn1/public_html/recommendingpeople.com/profilesummary.php on line 14
which is actually empty. I had a little doubt as well with your line 7. I filled it in as follows after no luck leaving "Users"
$MM_Username = "POST_Username"; // some string for the username, maybe from a POST variable
MM_Username is a session set from the log in page (username+pass) on the previous page which directs to this one. MM_Username worked on this page fine (on profilesummary) but only to filter the first table (rsusername) from username. I can't use it to filter the other tables that is why I need to establish userid for my global filtering variable. I hope you understand.
thankyou for your continued support.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: help with sessions please

Post by Neilos »

timoteo wrote:I had a little doubt as well with your line 7
Yes;

Code: Select all

$MM_Username = "User"; // some string for the username, maybe from a POST variable
was intended for you to set it to a suitable variable, I assumed you were getting it from a POST variable. I put it as a string, indicating that it should be a string. I should have made it more clear that I intended you to change this value.

So is $MM_Username an array? If so what are the indexes of the values?
timoteo wrote:unexpected T_STRING in /home/biomagn1/public_html/recommendingpeople.com/profilesummary.php on line 14 which is actually empty
Are you sure? That's strange.

Ok so I am now thoroughly confused lol.

I defined $MM_Username because you were using it in a query before it was initialised. Is $MM_Username saved in the session variable $_SESSION['MM_Username']?
timoteo wrote:$MM_Username = "POST_Username";
This is what I intended you to change it to (or something along the lines of), however you need to declare POST variables like this;

Code: Select all

$MM_Username = $_POST['Username'];
Ok forget everything lol.

I only looked a few lines into your code and I spotted what I thought were problems but you are telling me that they actually worked ok? So which part isn't working? Where are you trying to set the session and having trouble with it?
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: help with sessions please

Post by timoteo »

ok
MM_Username is set as a session name $_SESSION['MM_Username'] which was started on the previous page. (I'm no expert here, but the dreamweaver log in script does a pretty good job lol.) With this variable I could get the info displayed from my username table, however I need to set the session variable 'userid' to be able to retrieve the info from my other sql tables. This is what is not working. I get the info from all the users - I can't filter it because the $_SESSION['userid'] is null.
any ideas?
thankyou for all your time
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: help with sessions please

Post by timoteo »

The problem is still there:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/biomagn1/public_html/recommendingpeople.com/profilesummary.php on line 8

The code stands as follows
cheers

Code: Select all

<?php

session_start();

require_once('Connections/recommendingpeople.php');

$_SESSION['MM_Username']; // some string for the username, maybe from a POST variable

$query= "SELECT userid FROM rsusername WHERE username= $_SESSION['MM_Username']";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);

if ($numRows) {

         if ($numRows == 1) {
         $username = mysql_fetch_array($result, MYSQL_ASSOC);

                 $userid = $username['userid'];

                 $_SESSION['userid'] = $userid;

                 echo $_SESSION['userid'];

         } elseif ($numRows > 1) {
         echo "Lots of rows were returned";
         } else {
         echo "No rows were returned";
         }

} else {

         echo "No rows were returned";

}

?>
Last edited by Benjamin on Sat Jan 08, 2011 6:49 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: help with sessions please

Post by Neilos »

timoteo wrote:$_SESSION['MM_Username']; // some string for the username, maybe from a POST variable
Here you just call the session variable without assigning it to anything;

To fix this use;

Code: Select all

$username = $_SESSION['MM_Username'];

$query= "SELECT userid FROM rsusername WHERE username= '$username';";
However I think that I have confused the matter somewhat though.

Ok, so session variables are accessed with $_SESSION['index'] where index is the name of the index of the value stored in the $_SESSION array. If $_SESSION['userid'] is null then you need to set it (which is what I was attempting to do with my first code posting). If you have the username and this is unique, you can drag the id out of the database in the way I showed which is the way it looked as if you were trying to do it.

If usernames are not unique then you cannot do it this way.

I have just run this code on my server and it found a record and displayed the users id number with no errors;

Code: Select all

<?php

// Do your includes here, this is just me connecting to my database
include("database_connect.php");

$username = "Monkey";
// there is a record with username equal to Monkey, if this is changed then I get 'No rows were returned' this 
// should be the username you want to find. It should be set to the variable that you store the username in.

// This is the query using the string stored in the variable $username
$query= "SELECT userid FROM users WHERE username='$username';";
$result = mysql_query($query);

// this counts the rows, false if none
$numRows = mysql_num_rows($result);

// run if statements to check we have stuff retrieved in the query, we echo the id if it is found or a string if 
// either it isn't or many users are found
if ($numRows) {

        if ($numRows == 1) {
        $array = mysql_fetch_array($result, MYSQL_ASSOC);

                $userid = $array['id'];

                echo $userid;

        } elseif ($numRows > 1) {
        echo "Lots of rows were returned";
        } else {
        echo "No rows were returned";
        }

} else {

        echo "No rows were returned";

}

?>
So the problem is not with the code it is with what you are doing with it, namely I think, it is the variables you are trying to use. If you are happy to gain the users id from their username then go with this to drag it from the database.

You need to change the query to work with your tables and you need to use the appropriate variables for the ones that you have;

If you tell me if these assumptions are correct and correct them if wrong I will type the code for you;

1) you have the username of the client stored in the session variable $_SESSION['MM_Username'];

2) You have a table containing the usernames and userids of all your members and this is called rsusername

3) The field containing the userids is called userid

4) the field containing the usernames is called username
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: help with sessions please

Post by timoteo »

Hi,
All these assumptions are correct.
Thankyou. You are very kind
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: help with sessions please

Post by Neilos »

Code: Select all

<?php

session_start();

// Do your includes here
require_once('Connections/recommendingpeople.php');

$username = $_SESSION['MM_Username'];

// This is the query using the string stored in the variable $username
$query= "SELECT userid FROM rsusername WHERE username='$username';";
$result = mysql_query($query);

// this counts the rows, false if none
$numRows = mysql_num_rows($result);

// run if statements to check we have stuff retrieved in the query, we echo the id if it is found or a string if 
// either it isn't or many users are found
if ($numRows) {

        if ($numRows == 1) {

        // create an array containing the result of the mysql query result
        $array = mysql_fetch_array($result, MYSQL_ASSOC);

                // retrieve the userid from the array of the mysql query result
                $userid = $array['userid'];

                // assign the userid to the session variable
                $_SESSION['userid'] = $userid;

                // echo the session variable 'userid' for debugging purposes, you'll want to delete this eventually
                echo $_SESSION['userid'];

        } elseif ($numRows > 1) {
        // echo for debugging purposes, you'll want to delete this eventually
        echo "Lots of rows were returned";
        } else {
        // echo for debugging purposes, you'll want to delete this eventually
        echo "No rows were returned";
        }

} else {

        // echo for debugging purposes, you'll want to delete this eventually
        echo "No rows were returned";

}

?>
Try this on it's own first, then try it in your code replacing this part;

Code: Select all

<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
session_start();
?><?php
($_SESSION['userid'] = $rsusername.userid);
$query= 'SELECT userid FROM username WHERE username.username = $MM_Username';
$result = mysql_query($query);
echo gettype($array['userid']);?>
<?php echo $_SESSION['userid']; ?>
If you get any problems then post the full code, in code tags lol, and copy paste any errors you get.
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: help with sessions please

Post by timoteo »

This thing is still returning error!! ): I tried it as you said on it's own and here in context.
This was the result:

Parse error: syntax error, unexpected T_STRING in /home/biomagn1/public_html/recommendingpeople.com/profilesummary.php on line 16

Any ideas?
thanks a lot
here is all the code from this page:

Code: Select all

<?php

session_start();

// Do your includes here
require_once('Connections/recommendingpeople.php');

$username = $_SESSION['MM_Username'];

// This is the query using the string stored in the variable $username
$query= "SELECT userid FROM rsusername WHERE username='$username';";
$result = mysql_query($query);

// this counts the rows, false if none
$numRows = mysql_num_rows($result);

// run if statements to check we have stuff retrieved in the query, we echo the id if it is found or a string if 
// either it isn't or many users are found
if ($numRows) {

         if ($numRows == 1) {

         // create an array containing the result of the mysql query result
         $array = mysql_fetch_array($result, MYSQL_ASSOC);

                 // retrieve the userid from the array of the mysql query result
                 $userid = $array['userid'];

                 // assign the userid to the session variable
                 $_SESSION['userid'] = $userid;

                 // echo the session variable 'userid' for debugging purposes, you'll want to delete this eventually
                 echo $_SESSION['userid'];

         } elseif ($numRows > 1) {
         // echo for debugging purposes, you'll want to delete this eventually
         echo "Lots of rows were returned";
         } else {
         // echo for debugging purposes, you'll want to delete this eventually
         echo "No rows were returned";
         }

} else {

         // echo for debugging purposes, you'll want to delete this eventually
         echo "No rows were returned";

}

?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$colname_rsusername = "1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsusername = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsusername = sprintf("SELECT * FROM username WHERE username = '%s'", $colname_rsusername);
$rsusername = mysql_query($query_rsusername, $recommendingpeople) or die(mysql_error());
$row_rsusername = mysql_fetch_assoc($rsusername);
$totalRows_rsusername = mysql_num_rows($rsusername);

$colname_rsbusinessdetails = "1";
if (isset($_SESSION['userid'])){
  $colname_rsbusinessdetails = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
  }
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsbusinessdetails = sprintf("SELECT * FROM businessdetails WHERE userid = %s", $colname_rsbusinessdetails);
$rsbusinessdetails = mysql_query($query_rsbusinessdetails, $recommendingpeople) or die(mysql_error());
$row_rsbusinessdetails = mysql_fetch_assoc($rsbusinessdetails);
$totalRows_rsbusinessdetails = mysql_num_rows($rsbusinessdetails);

$colname_rsbusinessdescription = "1";
if (isset($_SESSION['userid'])) {
  $colname_rsbusinessdescription = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsbusinessdescription = sprintf("SELECT * FROM businessdescription WHERE userid = %s", $colname_rsbusinessdescription);
$rsbusinessdescription = mysql_query($query_rsbusinessdescription, $recommendingpeople) or die(mysql_error());
$row_rsbusinessdescription = mysql_fetch_assoc($rsbusinessdescription);
$totalRows_rsbusinessdescription = mysql_num_rows($rsbusinessdescription);

$colname_rsrecommendations = "1";
if (isset($_SESSION['userid'])) {
  $colname_rsrecommendations = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsrecommendations = sprintf("SELECT * FROM recommendations WHERE userid = %s", $colname_rsrecommendations);
$rsrecommendations = mysql_query($query_rsrecommendations, $recommendingpeople) or die(mysql_error());
$row_rsrecommendations = mysql_fetch_assoc($rsrecommendations);
$totalRows_rsrecommendations = mysql_num_rows($rsrecommendations);

$maxRows_rsrecommendations = 10;
$pageNum_rsrecommendations = 0;
if (isset($_GET['pageNum_rsrecommendations'])) {
  $pageNum_rsrecommendations = $_GET['pageNum_rsrecommendations'];
}
$startRow_rsrecommendations = $pageNum_rsrecommendations * $maxRows_rsrecommendations;

$colname_rsrecommendations = "1";
if (isset($_SESSION['userid'])) {
  $colname_rsrecommendations = (get_magic_quotes_gpc()) ? $_SESSION['userid'] : addslashes($_SESSION['userid']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_rsrecommendations = sprintf("SELECT * FROM recommendations WHERE userid = %s", $colname_rsrecommendations);
$query_limit_rsrecommendations = sprintf("%s LIMIT %d, %d", $query_rsrecommendations, $startRow_rsrecommendations, $maxRows_rsrecommendations);
$rsrecommendations = mysql_query($query_limit_rsrecommendations, $recommendingpeople) or die(mysql_error());
$row_rsrecommendations = mysql_fetch_assoc($rsrecommendations);
if (isset($_GET['totalRows_rsrecommendations'])) {
  $totalRows_rsrecommendations = $_GET['totalRows_rsrecommendations'];
} else {
  $all_rsrecommendations = mysql_query($query_rsrecommendations);
  $totalRows_rsrecommendations = mysql_num_rows($all_rsrecommendations);
}
$totalPages_rsrecommendations = ceil($totalRows_rsrecommendations/$maxRows_rsrecommendations)-1;

$queryString_rsrecommendations = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rsrecommendations") == false && 
        stristr($param, "totalRows_rsrecommendations") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rsrecommendations = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rsrecommendations = sprintf("&totalRows_rsrecommendations=%d%s", $totalRows_rsrecommendations, $queryString_rsrecommendations);
?>
<?php $MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Recommendingpeople/profilesummary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style3 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 36px;
	font-weight: bold;
	color: #FFFFFF;
}
.style7 {	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }
.style13 {
	font-size: 12px;
	font-style: italic;
}
.style18 {font-size: 14px; font-style: italic; color: #0000FF; }
.style20 {color: #0000FF}
.style24 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #0000FF;}
.style26 {font-size: 12px; font-style: italic; color: #0000FF; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style27 {font-size: 12px}
-->
</style>
</head>

<body>
<table width="100%" height="100%"  border="0" bgcolor="#FF6600">
  <caption>&nbsp;
  </caption>
  <tr>
    <td height="144" colspan="3"><p align="center"><img src="imagesrecommendingpeople/drawingrecommendingpeople.gif" alt="" width="750" height="125" align="top"></p>
    <p class="style3">Recommending people...</p></td>
  </tr>
  <tr>
    <td width="15%" height="372"><div align="center">
      </div></td>
    <td width="70%"  bgcolor="#FFFFFF"><p>&nbsp;</p>
      <form name="form1" method="post" action="">
        <div align="center">
          <table width="80%"  border="0">
            <tr>
              <td class="style12">First Name:</td>
              <td><?php echo $row_rsusername['firstname']; ?></td>
              <td class="style12">Last Name: </td>
              <td><?php echo $row_rsusername['lastname']; ?></td>
            </tr>
            <tr>
              <td class="style12">User Name:</td>
              <td><?php echo $row_rsusername['username']; ?></td>
              <td class="style12">Password:</td>
              <td><?php echo $row_rsusername['password']; ?></td>
            </tr>
            <tr>
              <td class="style12">E-mail:</td>
              <td><?php echo $row_rsusername['email']; ?></td>
              <td class="style12">&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <p>
            <input name="hiddenField4" type="hidden" value="<?php echo $row_rsusername['userid']; ?>">
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="150" height="35">
              <param name="BGCOLOR" value="">
              <param name="movie" value="userupdate.swf">
              <param name="quality" value="high">
              <embed src="userupdate.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="35" ></embed>
            </object>
          </p>
        </div>
      </form>      
      
      <p>&nbsp;</p>
      <p>&nbsp;     </p>
      <form name="form2" method="post" action="">
        <div align="center">
          <table width="80%"  border="0">
            <tr class="style12">
              <td><span class="style12">Business Category or profession: </span></td>
              <td><?php echo $row_rsbusinessdetails['businesscategory']; ?></td>
              <td>Business Name: </td>
              <td><?php echo $row_rsbusinessdetails['businessname']; ?></td>
            </tr>
            <tr class="style12">
              <td>Street number or name:</td>
              <td><?php echo $row_rsbusinessdetails['numbername']; ?></td>
              <td>Street:</td>
              <td><?php echo $row_rsbusinessdetails['street']; ?></td>
            </tr>
            <tr class="style12">
              <td>Town or Borough:</td>
              <td><?php echo $row_rsbusinessdetails['townborough']; ?></td>
              <td>City:</td>
              <td><?php echo $row_rsbusinessdetails['city']; ?></td>
            </tr>
            <tr class="style12">
              <td>County:</td>
              <td><?php echo $row_rsbusinessdetails['county']; ?></td>
              <td>State:</td>
              <td><?php echo $row_rsbusinessdetails['state']; ?></td>
            </tr>
            <tr class="style12">
              <td>Post Code: </td>
              <td><?php echo $row_rsbusinessdetails['postcode']; ?></td>
              <td>Country:</td>
              <td><?php echo $row_rsbusinessdetails['country']; ?></td>
            </tr>
            <tr class="style12">
              <td>Telephone:</td>
              <td><?php echo $row_rsbusinessdetails['tel1']; ?></td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <p>
            <input name="hiddenField" type="hidden" value="<?php echo $_SESSION['userid']; ?>">
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="150" height="35">
              <param name="BGCOLOR" value="">
              <param name="movie" value="buttoneditbusdetails.swf">
              <param name="quality" value="high">
              <embed src="buttoneditbusdetails.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="35" ></embed>
            </object>
</p>
          <p>&nbsp;          </p>
        </div>
      </form>      
      <form name="form3" method="post" action="">
        <div align="center">
          <table width="80%"  border="0">
            <tr class="style12">
              <td>Tel.2:</td>
              <td><?php echo $row_rsbusinessdescription['tel2']; ?></td>
              <td>Tel.3:</td>
              <td><?php echo $row_rsbusinessdescription['tel3']; ?></td>
            </tr>
            <tr class="style12">
              <td>Web page:</td>
              <td><?php echo $row_rsbusinessdescription['webpage']; ?></td>
              <td>Business Description Title:</td>
              <td><?php echo $row_rsbusinessdescription['businessdescriptiontitle']; ?></td>
            </tr>
            <tr class="style12">
              <td>Business Description: </td>
              <td colspan="3"><?php echo $row_rsbusinessdescription['businessdescription']; ?></td>
            </tr>
            <tr>
              <td class="style12">Photo:</td>
              <td colspan="3"><?php echo $row_rsbusinessdescription['photo']; ?></td>
            </tr>
          </table>
          <p>
            <input name="hiddenField2" type="hidden" value="<?php echo $row_rsbusinessdescription['userid']; ?>">
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="150" height="35">
              <param name="BGCOLOR" value="">
              <param name="movie" value="editbusinessdescription.swf">
              <param name="quality" value="high">
              <embed src="editbusinessdescription.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="35" ></embed>
            </object>
          </p>
        </div>
      </form>      
      
      <?php do { ?>
      <form name="form4" method="post" action="">
        <div align="center">
          <table width="94%"  border="0">
            <tr class="style12">
              <td width="14%">Business Category or Profession </td>
              <td width="12%">Business Name </td>
              <td width="10%">First Name </td>
              <td width="9%">Last Name </td>
              <td width="12%">Town or Borough</td>
              <td width="6%">City</td>
              <td width="9%">County</td>
              <td width="7%">State</td>
              <td width="10%">Country</td>
              <td width="5%">Tel.</td>
              <td width="6%">E-mail</td>
            </tr>
            <tr>
              <td><?php echo $row_rsrecommendations['businesscategory']; ?></td>
              <td><?php echo $row_rsrecommendations['businessname']; ?></td>
              <td><?php echo $row_rsrecommendations['firstname']; ?></td>
              <td><?php echo $row_rsrecommendations['lastname']; ?></td>
              <td><?php echo $row_rsrecommendations['townborough']; ?></td>
              <td><?php echo $row_rsrecommendations['city']; ?></td>
              <td><?php echo $row_rsrecommendations['county']; ?></td>
              <td><?php echo $row_rsrecommendations['state']; ?></td>
              <td><?php echo $row_rsrecommendations['country']; ?></td>
              <td><?php echo $row_rsrecommendations['tel']; ?></td>
              <td><?php echo $row_rsrecommendations['email']; ?></td>
            </tr>
          </table>
          <p>
            <input name="hiddenField3" type="hidden" value="<?php echo $row_rsrecommendations['userid']; ?>">
          </p>
        </div>
      </form>
      
            <div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="150" height="35">
                <param name="BGCOLOR" value="">
                <param name="movie" value="editrecommendations.swf">
                <param name="quality" value="high">
                <embed src="editrecommendations.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="35" ></embed>
              </object>
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="200" height="35">
                <param name="BGCOLOR" value="">
                <param name="movie" value="morerecommendations.swf">
                <param name="quality" value="high">
                <param name="SCALE" value="exactfit">
                <embed src="morerecommendations.swf" width="200" height="35" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" scale="exactfit" ></embed>
              </object>
              <br>
            </div>
            <table border="0" width="50%" align="center">
        <tr>
          <td width="23%" align="center">
            <?php if ($pageNum_rsrecommendations > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_rsrecommendations=%d%s", $currentPage, 0, $queryString_rsrecommendations); ?>">First</a>
          <?php } // Show if not first page ?>          </td>
          <td width="31%" align="center">
            <?php if ($pageNum_rsrecommendations > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_rsrecommendations=%d%s", $currentPage, max(0, $pageNum_rsrecommendations - 1), $queryString_rsrecommendations); ?>">Previous</a>
          <?php } // Show if not first page ?>          </td>
          <td width="23%" align="center">
            <?php if ($pageNum_rsrecommendations < $totalPages_rsrecommendations) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_rsrecommendations=%d%s", $currentPage, min($totalPages_rsrecommendations, $pageNum_rsrecommendations + 1), $queryString_rsrecommendations); ?>">Next</a>
          <?php } // Show if not last page ?>          </td>
          <td width="23%" align="center">
            <?php if ($pageNum_rsrecommendations < $totalPages_rsrecommendations) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_rsrecommendations=%d%s", $currentPage, $totalPages_rsrecommendations, $queryString_rsrecommendations); ?>">Last</a>
          <?php } // Show if not last page ?>          </td>
        </tr>
      </table>
      <?php } while ($row_rsrecommendations = mysql_fetch_assoc($rsrecommendations)); ?>
      <table border="0" width="50%" align="center">
        <table border="0" width="50%" align="center">
          <tr>
            <td width="23%" align="center"> First </td>
            <td width="31%" align="center"> Previous </td>
            <td width="23%" align="center"> Next </td>
            <td width="23%" align="center"> Last </td>
          </tr>
        </table>
      </table>
      <p>&nbsp;      </p>      </td>
    <td width="15%"><div align="center"><img name="" src="" width="134" height="367" alt=""></div></td>
  </tr>
  <tr>
    <td height="36%"><p align="center" class="style7"><strong>Recommending people...</strong></p>
    <p align="center" class="style7"><a href="mailto:administration@recommendingpeople.com">contact us</a></p></td>
    <td bgcolor="#FF6600
	"><div align="center"><img name="" src="" width="539" height="134" alt=""></div></td   bgcolor="#FF6600">
    <td><div align="center"><img name="" src="" width="112" height="97" alt=""></div></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsusername);

mysql_free_result($rsbusinessdetails);

mysql_free_result($rsbusinessdescription);

mysql_free_result($rsrecommendations);
?>
Last edited by Benjamin on Sun Jan 09, 2011 4:42 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: help with sessions please

Post by Benjamin »

:arrow: Use

Code: Select all

 tags when posting code in the forums.
Post Reply