473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 2085
ak1dnar
1,584 Recognized Expert Top Contributor
Welcome to TheScripts.com

Could you please post the Not working code snippets here.
Aug 25 '07 #2
pbmods
5,821 Recognized Expert Expert
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['AdditionalComm ents'] 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
7865
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 "languages" files and these are describes for things on my website. Example text looks like this:
6
12155
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 you and see if there are any improvments that i should make ;-) It should be fast and if possible compatible with todays modern browser-standards. It should be activated by the onload-event. This is my code, free for all to use:
7
19163
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 the browser. I even replaced all the newlines with <BR/> tags but eventhough I see the tags in my source, I don't get a line break in the output document. Any help would be greatly appreciated.
7
2751
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 tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the Server.EncodeHTML does not do that it seems). The problem is that users can use a special tag when editing the top to specify an area of the tip that will...
2
2536
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 the charcontrols option and chr(13) with success.. was using the following code: Dim s As String = MyTextbox.Text
1
3171
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 the charcontrols option and chr(13) with success.. was using the following code: Dim s As String = MyTextbox.Text
14
16487
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 bottom of the pages. What I'm trying to determine is : Which is better for printing info to a page based on dynamic variables? IE - if I have a boolean = True, should I use PrintF, print, echo to spit out the info?
3
3383
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, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
7
3627
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 most people use when they write static code (some people use <br>, but with xhtml you are required to close all tags), IE6 simply breaks to the next line like it is supposed to. However, with <br></br>, which is what is sometimes generated by...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.