14 Replies - 774 Views - Last Post: 02 July 2009 - 11:17 AM Rate Topic: -----

#1 peter yianni  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 310
  • Joined: 04-June 09

about sessions (resolved )

Posted 01 July 2009 - 01:28 PM

question i hope it a easy one to resolve

i have a page that works fine using sesson this one here
<?php 

include("../php-login-script-v1.0/session.php"); 

require_once('../Connections/stablemaster.php');



$user_name = $_SESSION['user'];

$user_id = $_SESSION['uid'];





if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

	$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

	case "text":

	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

	  break;	

	case "long":

	case "int":

	  $theValue = ($theValue != "") ? intval($theValue) : "NULL";

	  break;

	case "double":

	  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

	  break;

	case "date":

	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

	  break;

	case "defined":

	  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

	  break;

  }

  return $theValue;

}

}



mysql_select_db($database_stablemaster, $stablemaster);

$query_Recordset1 = "SELECT stable_name, user_email, country FROM users WHERE id='".$user_id."'";

$Recordset1 = mysql_query($query_Recordset1, $stablemaster) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);



mysql_select_db($database_stablemaster, $stablemaster);

$query_horsehistory = "SELECT * FROM horse_stats WHERE stable_name = '".$row_Recordset1['stable_name']."'";

$horsehistory = mysql_query($query_horsehistory, $stablemaster) or die(mysql_error());

$row_horsehistory = mysql_fetch_assoc($horsehistory);

$totalRows_horsehistory = mysql_num_rows($horsehistory);



mysql_select_db($database_stablemaster, $stablemaster);

$query_JOCKSTATS = "SELECT * FROM jocky_stats WHERE stable_name = '".$row_Recordset1['stable_name']."'";

$JOCKSTATS = mysql_query($query_JOCKSTATS, $stablemaster) or die(mysql_error());

$row_JOCKSTATS = mysql_fetch_assoc($JOCKSTATS);

$totalRows_JOCKSTATS = mysql_num_rows($JOCKSTATS);



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



<html>

<head>

<title>Stable Stats</title>

<meta http-equiv="Expires" content="0" />

	<META HTTP-EQUIV="cache-control" CONTENT="no-cache" />

<link href="file:///C|/wamp/www/WEBISTE BUILDING/Style Sheets/Fonts.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

.Fonts tr td {

	color: #000;

}

#stable_finances tr td h1 {

	font-variant: small-caps;

	color: #FF0;

}

#stable_finances2 tr td h2 {

	background-color: #30F;

	color: #FF0;

}

-->

</style>

<link href="file:///C|/wamp/www/WEBISTE BUILDING/Style Sheets/heading2.css" rel="stylesheet" type="text/css" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<style type="text/css">

<!--

body {

	background-color: #BFEBFF;

}

#stable_stats tr td div h2 {

	color: #00F;

}

#stable_stats tr td table tr td div {

	color: #FFF;

}

-->

</style></head>



<body onload="startTime()">

<div align="center">

<div align="center">

  <table width="100%" border="0" cellspacing="2" cellpadding="2">

	<tr>	</tr>

  </table>

</div>

<div id="txt"></div>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

	<td bgcolor="#BFEBFF"><form name="form1" method="post" action="">

	  <table width="60%" border="0" align="center" cellpadding="1" cellspacing="1" id="stable_stats">

		<tr>

		  <td colspan="2" bgcolor="#BFEBFF"><div align="center">

			<h2>Stable Stats</h2>

		  </div></td>

		  </tr>

		<tr>

		  <td>Stable Name</td>

		  <td><label for="stable_name"></label>

<input name="stable_name" type="text" id="stable_name" value="<?php echo $row_Recordset1['stable_name']; ?>" size="30" maxlength="45"  /></td>

		  </tr>

		<tr>

		  <td>Email</td>

		  <td><label for="email"></label>

<input name="email" type="text" id="email" value="<?php echo $row_Recordset1['user_email']; ?>" size="30" maxlength="40"  /></td>

		  </tr>

		<tr>

		  <td>country</td>

		  <td><label for="country"></label>

<input name="country" type="text" id="country" value="<?php echo $row_Recordset1['country']; ?>" size="30" maxlength="20" /></td>

		  </tr>

		</table>

	  </form></td>

	</tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

	<td><form name="form1" method="post" action="">

	  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Fonts" id="stable_stats">

		<tr>

		  <td width="100%" bgcolor="#BFEBFF"><div align="center">

			<h2> </h2>

			<h2>Current Horses</h2>

		  </div></td>

		  </tr>

		<tr>

		  <td bgcolor="#FFFFFF">

			<table width="100%" border="1" cellpadding="1" cellspacing="1">

			  <tr>

				<td width="13%" bgcolor="#0000FF"><div align="center">Name</div></td>

				<td width="10%" bgcolor="#0000FF"><div align="center">Age</div></td>

				<td width="10%" bgcolor="#0000FF"><div align="center">Gen</div></td>

				<td width="11%" bgcolor="#0000FF"><div align="center">Bred</div></td>

				<td width="10%" bgcolor="#0000FF"><div align="center">Xp</div></td>

				<td width="10%" bgcolor="#0000FF"><div align="center">Ran</div></td>

				<td width="11%" bgcolor="#0000FF"><div align="center">Won</div></td>

				<td width="12%" bgcolor="#0000FF"><div align="center">Shown</div></td>

				<td width="13%" bgcolor="#0000FF"><div align="center">Winnings</div></td>

				</tr>

			  <?php do { ?>

				<tr>

				  <td nowrap><a href="../Horse_history.php?horse=<?php echo $row_horsehistory['name_id']; ?>"><?php echo $row_horsehistory['name_id']; ?></a></td>

				  <td><?php echo $row_horsehistory['age']; ?></td>

				  <td><?php echo $row_horsehistory['gen']; ?></td>

				  <td><?php echo $row_horsehistory['bred']; ?></td>

				  <td><?php echo $row_horsehistory['xp']; ?></td>

				  <td><?php echo $row_horsehistory['ran']; ?></td>

				  <td><?php echo $row_horsehistory['won']; ?></td>

				  <td><?php echo $row_horsehistory['shown']; ?></td>

				  <td><?php echo $row_horsehistory['winnings']; ?></td>

				  </tr>

				<?php } while ($row_horsehistory = mysql_fetch_assoc($horsehistory)); ?>

			  </table></td>

		</tr>

		<tr>

		  <td bgcolor="#BFEBFF"><div align="center">

			<h2> </h2>

			<h2>Current Jockeys</h2>

		  </div></td>

		  </tr>

		<tr>

		  <td><table width="100%" border="1" align="center" cellpadding="1" cellspacing="1">

			<tr>

			  <td bgcolor="#0000FF"><div align="center">Jocky Name</div></td>

			  <td bgcolor="#0000FF"><div align="center">Age</div></td>

			  <td bgcolor="#0000FF"><div align="center">Run</div></td>

			  <td bgcolor="#0000FF"><div align="center">Won</div></td>

			  <td bgcolor="#0000FF"><div align="center">Place</div></td>

			  <td bgcolor="#0000FF"><div align="center">Moral</div></td>

			  <td bgcolor="#0000FF"><div align="center">Rating</div></td>

			  <td bgcolor="#0000FF"><div align="center">Winnings</div></td>

			  </tr>

			<?php do { ?>

			  <tr>

				<td bgcolor="#FFFFFF"><a href="../jocky_history.php?jocky=<?php echo $row_JOCKSTATS['Jocky_name']; ?>"><?php echo $row_JOCKSTATS['Jocky_name']; ?></a></td>

				<td bgcolor="#FFFFFF"><?php echo $row_JOCKSTATS['age']; ?></td>

				<td bgcolor="#FFFFFF"><?php echo $row_JOCKSTATS['run']; ?></td>

				<td bgcolor="#FFFFFF"><?php echo $row_JOCKSTATS['won']; ?></td>

				<td bgcolor="#FFFFFF"><?php echo $row_JOCKSTATS['place']; ?></td>

				<td bgcolor="#FFFFFF"><?php echo $row_JOCKSTATS['moral']; ?></td>

				<td bgcolor="#FFFFFF"><?php echo $row_JOCKSTATS['rating']; ?></td>

				<td bgcolor="#FFFFFF"><?php echo $row_JOCKSTATS['winnings']; ?></td>

				</tr>

			  <?php } while ($row_JOCKSTATS = mysql_fetch_assoc($JOCKSTATS)); ?>

			</table><h2> </h2></td>

		</tr>

		</table>

	  </form></td>

	</tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

	<td> </td>

	</tr>

</table>



</div>

</body>

</html>

<?php



mysql_free_result($horsehistory);



mysql_free_result($JOCKSTATS);



mysql_free_result($Recordset1);

?>



i want to make this one use the same session but its just not happening.
i will put the pages as uploads the stable statistics.php is fine
the horse summary is not .
the page itself is ok but it comes up with all the horses instead of just the users horses here is the page

<?php require_once('Connections/stablemaster.php');

require_once('../Connections/stablemaster.php');

session_start();

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
	$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
	case "text":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	  break;	
	case "long":
	case "int":
	  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
	  break;
	case "double":
	  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
	  break;
	case "date":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	  break;
	case "defined":
	  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
	  break;
  }
  return $theValue;
}
}

mysql_select_db($database_stablemaster, $stablemaster);
$query_Recordset1 = "SELECT * FROM horse_stats";
$Recordset1 = mysql_query($query_Recordset1, $stablemaster) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>Horse summary</title>
<style type="text/css">
<!--
body {
	background-color: #BFEBFF;
	color: #000;
}
-->
</style>

<link href="Style Sheets/FONTBLUE.css" rel="stylesheet" type="text/css" /></head>


<?php 

do { 

?>
		<table width="900" border="10" cellspacing="5" cellpadding="1">
		<tr>
		<td width="150" bgcolor="#CCCCCC"><h3 align="center">
	  
	  <a href="../Horse_history.php?horse=<?php echo $row_horsehistory['name_id']; ?>">
	  
	  <?php echo $row_Recordset1['name_id']; ?></a></h3></td>
	  
	  <td nowrap="nowrap" bgcolor="#CCCCCC"><h4 align="center">
	  Overall Rating</h4></td>
	 
	  <td nowrap="nowrap" bgcolor="#CCCCCC"><h3 align="center">	  
	  <?php echo $row_Recordset1['xp']; ?></h3></td>
	  
	<td nowrap="nowrap" bgcolor="#CCCCCC"><h3 align="center">	  
	Date      Time      Details</h3></td>
	
	</tr>
	<tr>
	<td width="150" height="150" align="center" valign="top"><div align="center">
	  
	<img src='../Horse image/<?php echo $row_Recordset1["image"]?>' /></div></td>
	  
	<td width="120" valign="top" nowrap="nowrap" class="FONTBLUE">
		
		Age<br />
		Gen<br />
		Medical:<br />
		Physical:<br />
		Ran / Won<br />
		Career earnings:<br />
		Latest race:</td>
		
	  <td width="150" valign="top" nowrap="nowrap">
	 (<?php echo $row_Recordset1['age']; ?>)<br />
	  <?php echo $row_Recordset1['gen']; ?><br />
	  <?php echo $row_Recordset1['medical_condition']; ?><br />
	  <?php echo $row_Recordset1['physical_condition']; ?><br />
	 (<?php echo $row_Recordset1['ran']; ?>)(		
	  <?php echo $row_Recordset1['won']; ?>)<br />
	  <?php echo $row_Recordset1['career_earnings']; ?><br />
	  <?php echo $row_Recordset1['latest_race']; ?><br /></td>
	  
  <td width="480" align="left" valign="top" nowrap="nowrap"></td>
  </tr>
  </table>
 
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>



i would apritiate the help as there is a lot of pages that will need to use the same sessions

Attached File(s)


This post has been edited by peter yianni: 02 July 2009 - 11:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: about sessions (resolved )

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: about sessions (resolved )

Posted 01 July 2009 - 02:16 PM

You need to call session_start() within the second script.
Was This Post Helpful? 0
  • +
  • -

#3 peter yianni  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 310
  • Joined: 04-June 09

Re: about sessions (resolved )

Posted 01 July 2009 - 02:18 PM

View PostMageUK, on 1 Jul, 2009 - 01:16 PM, said:

You need to call session_start() within the second script.


its there

<?php require_once('Connections/stablemaster.php');

require_once('../Connections/stablemaster.php');

session_start();

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: about sessions (resolved )

Posted 01 July 2009 - 02:31 PM

Ah duh, it's late.

Under session_start(), try adding print_r($_SESSION);, if it prints out correct values then you know it's nothing to do with session handling and is to do with the query or something different :)
Was This Post Helpful? 0
  • +
  • -

#5 peter yianni  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 310
  • Joined: 04-June 09

Re: about sessions (resolved )

Posted 01 July 2009 - 02:37 PM

View PostMageUK, on 1 Jul, 2009 - 01:31 PM, said:

Ah duh, it's late.

Under session_start(), try adding print_r($_SESSION);, if it prints out correct values then you know it's nothing to do with session handling and is to do with the query or something different :)


Array ( [user] => andrew [uid] => 2 )

got that which is corect
but theres a horse from another stable in there ? so sessions is not the problem
Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: about sessions (resolved )

Posted 01 July 2009 - 09:59 PM

You need Start Session at top of every page

page1.php
if(!isset($_SESSION))
{
	session_start();
}
$_SESSION['username']= 'anything'; // declaring and assigning value to session variable




page2.php
if(!isset($_SESSION))
{
	session_start();
}
echo $_SESSION['username']; //printing session in our page



and i also attached your files.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#7 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: about sessions (resolved )

Posted 02 July 2009 - 12:06 AM

View Postnoorahmad, on 1 Jul, 2009 - 08:59 PM, said:

You need Start Session at top of every page

page1.php
if(!isset($_SESSION))
{
	session_start();
}
$_SESSION['username']= 'anything'; // declaring and assigning value to session variable




page2.php
if(!isset($_SESSION))
{
	session_start();
}
echo $_SESSION['username']; //printing session in our page



and i also attached your files.

Can you actually read? The session is fine.
Was This Post Helpful? 0
  • +
  • -

#8 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: about sessions (resolved )

Posted 02 July 2009 - 12:18 AM

Quote

Can you actually read? The session is fine.

is there any wrong? can you solve it? may be i am in basic of PHP can make it advance?
Was This Post Helpful? 0
  • +
  • -

#9 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: about sessions (resolved )

Posted 02 July 2009 - 12:24 AM

View Postnoorahmad, on 1 Jul, 2009 - 11:18 PM, said:

Quote

Can you actually read? The session is fine.

is there any wrong? can you solve it? may be i am in basic of PHP can make it advance?

Yes I can solve it because I don't guess everything.

peter_yianni, on the second page, under the mysql_select_db and where $Recordset1 is created, add this:
$stable_nameQ = mysql_query("SELECT stable_name FROM users WHERE id='".$_SESSION['uid']."'");
$stable_nameA = mysql_fetch_assoc($stable_nameQ);
$query_Recordset1 = "SELECT * FROM horse_stats WHERE `stable_name` = '".$stable_nameA['stable_name']."';";


Replace the query_Recordset1 line with the above.
Was This Post Helpful? 0
  • +
  • -

#10 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Re: about sessions (resolved )

Posted 02 July 2009 - 12:51 AM

$stable_nameQ = mysql_query("SELECT stable_name FROM users WHERE id='".$_SESSION['uid']."'");



if it occurs error..then

$id = $_SESSION['uid'];
$stable_nameQ = mysql_query("SELECT stable_name FROM users WHERE id= $id");


if you want then ..........

U need to assign an array where ur session values were created. After array declaration session value will print.
Was This Post Helpful? 0
  • +
  • -

#11 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: about sessions (resolved )

Posted 02 July 2009 - 12:53 AM

??? Why would an error occur??
Was This Post Helpful? 0
  • +
  • -

#12 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,880
  • Joined: 10-May 07

Re: about sessions (resolved )

Posted 02 July 2009 - 01:03 AM

Because there are single quotes within single quotes. That will probably be ok since the quote tags are closed prior to using the 2nd set of single quotes inside of the Session array.

Even if that doesn't kill it, I wouldn't use the Sessions variable straight into the mysql statement. I would put it to a variable after testing it for blank, clearing html & any other garbage.
Was This Post Helpful? 0
  • +
  • -

#13 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: about sessions (resolved )

Posted 02 July 2009 - 01:06 AM

There's nothing to escape? The session is being entered external from the string via concatenation, and the value of session is being added from a seperate script where this sort of filtering should be performed.

To be safe"r" a better option would be to just do:
$stable_nameQ = mysql_query("SELECT `stable_name` FROM `users` WHERE `id` = '" . mysql_real_escape_string($_SESSION['uid']) . "'");


But the relevant filtering should be applied already once the login has commenced.

Aaaah you edited, seeeeee :P

This post has been edited by MageUK: 02 July 2009 - 01:07 AM

Was This Post Helpful? 1
  • +
  • -

#14 peter yianni  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 310
  • Joined: 04-June 09

Re: about sessions (resolved )

Posted 02 July 2009 - 11:13 AM

View PostMageUK, on 1 Jul, 2009 - 11:24 PM, said:

View Postnoorahmad, on 1 Jul, 2009 - 11:18 PM, said:

Quote

Can you actually read? The session is fine.

is there any wrong? can you solve it? may be i am in basic of PHP can make it advance?

Yes I can solve it because I don't guess everything.

peter_yianni, on the second page, under the mysql_select_db and where $Recordset1 is created, add this:
$stable_nameQ = mysql_query("SELECT stable_name FROM users WHERE id='".$_SESSION['uid']."'");
$stable_nameA = mysql_fetch_assoc($stable_nameQ);
$query_Recordset1 = "SELECT * FROM horse_stats WHERE `stable_name` = '".$stable_nameA['stable_name']."';";


Replace the query_Recordset1 line with the above.



thank u its all working much apritiated also thanks the everyone one else who helped
Was This Post Helpful? 0
  • +
  • -

#15 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: about sessions (resolved )

Posted 02 July 2009 - 11:17 AM

No problem mate glad you have it sorted :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1