Jump to content

Problem with session


franknu

Recommended Posts

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] => 
)

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$_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

 

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.