0

hi i have one page where i will get Categories of Products and i want to make session of those Categories..But when i referesh page session break...my code is..

session_start();
	$_Session['P_Category'] = $_GET['P_Category']; ////line 8
	$P_Category =$_Session['P_Category'];
	
	$query = "select * from tblProducts_info where P_Category = '$P_Category'";

$result = mysql_query($query);

if(!$result)
{
	die('query:invalid Query: '.mysql_error());
}

and error comes that...
Notice: Undefined index: P_Category in C:\wamp\www\New\electronix\Breaks\Center_Content.php on line 8

6
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by mamdouh ramadan
0

Hi,

In line 2 when you define your session:

TRY:
$_SESSION -> IN UPPERCASE

Instead of:
$_Session -> in lowercase

Edited by klemme: n/a

0

The code should look like this after editing

session_start();
	$_SESSION['P_Category'] = $_GET['P_Category']; ////line 8
	$P_Category = $_SESSION['P_Category'];
 
	$query = "select * from tblProducts_info where P_Category = '$P_Category'";
 
$result = mysql_query($query);
 
if(!$result)
{
	die('query:invalid Query: '.mysql_error());
}
0

I did it....but i still get this error
Notice: Undefined index: P_Category in C:\wamp\www\New\electronix\Breaks\Center_Content.php on line 8

i want to store P_Category in session.what should i do?..when i referesh page so error comes..

0

session_start() must be the first thing on your page.

<?php
session_start();  // nothing can be before this line
// which appears to be line 7 in your program.  you should post full codes for debugging info, because your line 8 is our line 2.  that should do it for you though, move your session_start() call to be line 1 of your program.
0

Did you already pass the get vars for '$_GET' ? If your url has not include 'P_Category', '$_SESSION' will undefined variable.

$_SESSION['P_Category'] = isset($_GET['P_Category']) ? $_GET['P_Category'] : 'default'; // if you've already P_Category with url, assign to the session, otherwise, default value will assign to the session
0

$query = "select * from tblProducts_info where P_Category = '{$P_Category}'";
this will solve the appeared error

if you want it to be saved in the session after the sql fetched like:
while($result = mysql_fetch_array(mysql_query($query)))
{
$_SESSION = $result;
}
this is a simple way and you can make more comlicated and advanced using OOP by making a class database doing this for you... aw the first line i wrote is what will help you avoid the error

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.