franknu Posted June 15, 2007 Share Posted June 15, 2007 Ok, i am going to need some help with a session, i really dont know what the problem is here is my code for page one which work fine <?php session_start(); $_SESSION['BusinessName'] ='$BusinessName'; $_SESSION['BusinessName']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#E5E5E5" link="#FFFFFF" topmargin="0"> and when i do this: <center> <?php $_SESSION['BusinessName']; ?> <pre>_SESSION:<?php print_r($_SESSION); ?></pre> I dispay this_SESSION:Array ( [businessName] => Cristal Bar Restaurant ) code for page2 here it is <? $BusinessName = addslashes($_POST['BusinessName']); $from = addslashes($_POST['from']); $status= addslashes($_POST['status']); $subject= addslashes($_POST['subject']); $message= addslashes($_POST['message']); $BusinessName= $_SESSION['BusinessName']; if(isset($_SESSION['BusinessName'])){ $query = "INSERT INTO `messages` (`BusinessName`,`date`,`from`,`status`,`subject`,`message`) VALUES ('".$_SESSION['BusinessName']."','".$date."','".$from."', '".$status."','".$subject."', '".$message."')"; $result = mysql_query($query); echo mysql_error(); if($result) { echo mysql_affected_rows()." .Your Message have been sent. We will get back to you. <br>"; } } ?> <center> <?php $_SESSION['BusinessName']; $_SESSION['User_Name']; $_SESSION['Password']; ?> <pre>_SESSION:<?php print_r($_SESSION); ?></pre> this display _SESSION:Array ( [businessName] => ) Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/ Share on other sites More sharing options...
Caesar Posted June 15, 2007 Share Posted June 15, 2007 Make sure you don't forget... <?php session_start(); ?> ...in pages where you're going to use the session variables. I don't see it on page two. Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-275452 Share on other sites More sharing options...
franknu Posted June 15, 2007 Author Share Posted June 15, 2007 sorry, i just didnt place it on the code but this is how the top looks like <?php session_start(); $_SESSION['BusinessName']; $_SESSION['User_Name']; $_SESSION['Password']; ?> <html> <head> <title>Send Message</title> Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-275486 Share on other sites More sharing options...
wildteen88 Posted June 16, 2007 Share Posted June 16, 2007 Why are you placing these variables on their line and then not doing anything with them? $_SESSION['BusinessName']; $_SESSION['User_Name']; $_SESSION['Password']; I guess you are doing it to initiate the variables. You don't need to initialize them before use. PHP wont do any think with them. PHP automatically initializes session variables when you call session_start() function. I would just remove those lines and any similar lines. Also I cannot see how the two blocks of code for the two pages relate to each other. On the first page you create a session var called BusinessName with the value from $BusinessName variable - where is that variable set to?. Then you have about two instances of $_SESSION['BusinessName']; on their own (for no apparent reason). After that you print out the contents of the session. Which miraculously reports back a value. This is where it gets confusing. ON page 2 you are now dealing with _POST data. Where does that come from? I did not see you using a form on page1. See I cannot really help as I cannot see any connection between the two pages and so I cannot help you fix the problem you are having. If you could repost post your question in a manner that what ever you code you post actually links together in some way that I/We can understand it in order to help you. Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-275748 Share on other sites More sharing options...
franknu Posted June 16, 2007 Author Share Posted June 16, 2007 Ok, I looks like i am destroying the session BusinessName on page 2 so my problem is on page two with the variable BusinessName Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-275944 Share on other sites More sharing options...
king arthur Posted June 16, 2007 Share Posted June 16, 2007 Well currently the first thing you're doing on page one is $_SESSION['BusinessName'] ='$BusinessName'; but $BusinessName will not be defined, so you've just assigned an undefined value to the session variable. Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-275946 Share on other sites More sharing options...
franknu Posted June 16, 2007 Author Share Posted June 16, 2007 $_SESSION['BusinessName'] =$BusinessName; i under the session $BusinessName = (isset($_GET['BusinessName']) ? $_GET['BusinessName'] : ''); $Slogan = (isset($_GET['Slogan']) ? $_GET['Slogan']:''); $Business_Address = (isset($_GET['Business_Address']) ? which is where i am assigning a value, i just added the part of the codes where the problem might be also i think that the main problem is on page2 because i can display the value of $_SESSION['BusinessName'] ='$BusinessName'; on page1 Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-275959 Share on other sites More sharing options...
king arthur Posted June 16, 2007 Share Posted June 16, 2007 It's not much good posting snippets of code from each page and leaving out other critical parts, we can't see how what you've posted actually works or how it might not be working. Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-275975 Share on other sites More sharing options...
franknu Posted June 16, 2007 Author Share Posted June 16, 2007 ok here is my full code for page2 <?php session_start(); $_SESSION['BusinessName']; ?> <html> <head> <title>Send Message</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#E5E5E5"> <?php $db = mysql_connect($host, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $from = addslashes($_POST['from']); $status= addslashes($_POST['status']); $subject= addslashes($_POST['subject']); $message= addslashes($_POST['message']); $BusinessName= $_SESSION['BusinessName']; if(isset($_SESSION['BusinessName'])){ $query = "INSERT INTO `messages` (`BusinessName`,`date`,`from`,`status`,`subject`,`message`) VALUES ('".$_SESSION['BusinessName']."','".$date."','".$from."', '".$status."','".$subject."', '".$message."')"; $result = mysql_query($query); echo mysql_error(); if($result) { echo mysql_affected_rows()." .Your Message have been sent. We will get back to you. <br>"; } } ?> <center> <pre>_SESSION:<?php print_r($_SESSION); ?></pre> <table width="200" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td valign="top"> <?php include("includefiles/banner.php"); ?> <table width="778" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="778" valign="top"> <table width="778" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" bgcolor="#f90102"> <?php echo "<h1><font color='ffffff'><marquee>$BusinessName </marquee></font></h1>"; ?> </td> </tr> </table></td> Quote Link to comment https://forums.phpfreaks.com/topic/55757-problem-with-session/#findComment-276044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.