473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

echo $_SESSION returns <br /> and I can't fix it

I've racked my head on this all day long. I've been using php for 3 days now and this is the first hang up I've had and it's driving me nuts, but I can't pull myself away from trying to fix the problem. I need help or a push in the right direction.

I have a contact form and a validate form. I'll keep this short and sweet, if it can work for one field, I can figure it out for the rest.

I have session_start() at the top of both form and validate pages to start with. On the form page I have

Expand|Select|Wrap|Line Numbers
  1. <input name="Name" type="text" id="Name" value="<?php echo $_SESSION['Name']; ?>">
If you visit the form page before the validate page has a chance to create the sessions it returns the following in each field
Expand|Select|Wrap|Line Numbers
  1. <br />
In the textfield box it shows
Expand|Select|Wrap|Line Numbers
  1. <br />
  2. <b>Notice</b>:  Undefined index:  AdditionalComments in <b>/myservers/mydir/htdocs/contact2.php</b> on line <b>208</b><br />
Line 208 is just the same as what was used for the input name, a php echo of the session and it's key.

I'm stumped, I've tried, searching for the tag, if/then statements for null values in the session. This is one problem that is easier with good ol ASP, I don't know what im missing. I'm trying to just show a blank form when a user views it for the first time, after they submit, it's validated, if it's good fine, if not it will re-direct and then keep state with the sessions for values. Instead it just shows that <br /> tag. Help please, I've been at this since this morning.
Aug 25 '07 #1
2 2064
ak1dnar
1,584 Expert 1GB
Welcome to TheScripts.com

Could you please post the Not working code snippets here.
Aug 25 '07 #2
pbmods
5,821 Expert 4TB
Heya, Kaotik.

You're getting this notice because you're trying to output an undefined index in your _SESSION array. In other words, the first time the User accesses the page, $_SESSION['AdditionalComments'] is undefined, but you are trying to echo() it.

You have a couple of options.

You can add this to the top of your form page to initialize your array:
Expand|Select|Wrap|Line Numbers
  1. if( empty($_SESSON) )
  2. {
  3.     $_SESSION =
  4.     array
  5.     (
  6.         'Name' => '',
  7.         .
  8.         .
  9.         .
  10.         'AdditionalComments' => ''
  11.     )
  12. }
  13.  
Or you can suppress errors for the echo statements:
Expand|Select|Wrap|Line Numbers
  1. <input name="Name" ... value="<?php @echo $_SESSION['Name']; ?>">
  2.  
Or you can simply turn off notices:
Expand|Select|Wrap|Line Numbers
  1. error_reporting(E_ALL ^ E_NOTICE);
  2.  
Aug 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my...
6
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with...
7
by: noor.rahman | last post by:
I have an XML file that stores data from an HTML form. I use XSL to display the data in HTML format. The data may have newline characters. However, XSL is not displaying the newlines properly in...
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
2
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all...
1
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all...
14
by: Khai | last post by:
I'm an extreme newbie, and have been nosing around the PHP.Net site for a few days. Only, the search function returns alot of information that's not truly relevant due to Coding samples at the...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
7
by: Nathan Sokalski | last post by:
Something that I recently noticed in IE6 (I don't know whether it is true for other browsers or versions of IE) is that it renders <br/and <br></br> differently. With the <br/version, which is what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.