Session Help
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
Farhad.idrees
Junior Poster in Training
63 posts since Dec 2010
Reputation Points: 11
Solved Threads: 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());
}
Nahiyan
Junior Poster in Training
65 posts since Sep 2009
Reputation Points: 17
Solved Threads: 5
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..
Farhad.idrees
Junior Poster in Training
63 posts since Dec 2010
Reputation Points: 11
Solved Threads: 0
Nahiyan
Junior Poster in Training
65 posts since Sep 2009
Reputation Points: 17
Solved Threads: 5
Did you already pass the get vars for '$_GET['P_Category']' ? If your url has not include 'P_Category', '$_SESSION['P_Category']' 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
Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139