473,396 Members | 1,608 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,396 software developers and data experts.

Notice: Undefined index message

New to .php so need script help.
I want to know how to stop this being displayed when I click submit.

Notice: Undefined index: homeowner in E:\domains\r\...\user\htdocs\...\form.php on line 166

I have an array which takes filled in fields and blank fields and sends them via email.
I DON'T need the user to fill in all the fields which is resulting in this notice on every field that is not filled in. I do need the fields to be sent tho' even if blank.
I have posted the scipt i have managed to piece together if this will help.
somehow I need the blank fields not to show me this notice.
I have started my .php script with this
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $to = $_REQUEST['sendto'] ; 
  3. $from = $_REQUEST['Email'] ;
  4. $name = $_REQUEST['Member_Name'] ; 
  5. $headers = "From: $from"; 
  6. $subject = "......"; 
  7.  
  8. $fields = array(); //I HAVE ABOUT 100 FIELDS
  9.  
  10. $body = ".........:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
  11.  
  12. $headers2 = "From: .......@....."; 
  13. $subject2 = "Thank-you ......."; 
  14. $autoreply = "Somebody.......";
  15.  
  16. if($from == '') {print "You have not ....";} 
  17. else { 
  18. if($name == '') {print "You have not .......";} 
  19. else { 
  20. $send = mail($to, $subject, $body, $headers); 
  21. $send2 = mail($from, $subject2, $autoreply, $headers2); 
  22. if($send) 
  23. {header( "Location: http.....com/.../thankyou.html" );} 
  24. else 
  25. {print "We encountered an error sending your mail, please notify ...@...."; } 
  26.  }
  27.  }
  28. ?>
Sorry, but completey new to .php so I have no idea what i have to do to stop this notice from displaying, or how to script it into the above.
Any help will be appreciated.
Nov 28 '08 #1
11 6695
Markus
6,050 Expert 4TB
Stealthmode666,

For the benefit of our experts and yourself, it is a posting guidelines that all users use [code] tags when posting code. This makes the code easier to read and, in turn, helps our experts answer your questions.

An easy way to do this is to highlight the code in the textarea and then hit the '#' button at the top of the textarea.

Please read the Posting Guidlines so you're more familiar with how things work.

Thanks,
Moderator.
Nov 28 '08 #2
Markus
6,050 Expert 4TB
You should check with isset() that the array index exists - or you could use ternary operator to set a default value if it doesn't exist.

Consider the following:

Expand|Select|Wrap|Line Numbers
  1. // This will give an index warning because the index doesn't exist.
  2. $Oh_Crap = $_GET['this_index_doesnt_exist'];
  3.  
  4. // This helps
  5. if( isset ($_GET['imaginary_index'] ) )
  6. {
  7.     // index exists; play with it.
  8. }
  9. else
  10. {
  11.     // index doesn't exist; shout at it!
  12. }
  13.  
  14. // or this:
  15. $This_is_better = ($_GET['imaginary_index'] ? $_GET['imaginary_index'] : "Index doesn't exist");
  16.  
Any questions?

Thanks,
Markus.
Nov 28 '08 #3
Thanks for that, but I have no idea where to insert this?
I am trying to learn as fast as I can and understand very simple things. I can code in html, css etc but beyond that i'm really struggling, 3 days ago I managed to create a webform, upload it to a webhost, and get the form data to be sent back to me via email and the script above. I am trying to cram in as many tutorials as I can but to be honest a lot of them are incomplete and I need to see them from beginning to end - maybe i'm looking at the wrong websites? sorry for being so dumb but I have to start somewhere.
Nov 28 '08 #4
Markus
6,050 Expert 4TB
@stealthmode666
Ok, the best sites for learning PHP:
  • Tizag.com
  • W3schools.com
  • PHP.net

Be sure to use them!

Ok, so what I was saying before was: you need to check the the array index actually has a value. To do that, we can use a few things, but mainly we use isset(). However, I think that'll fatten your code up a bit. Instead, use the ternary operator to assign a default value to your variable if there is no value at the array index. Like follows:

Expand|Select|Wrap|Line Numbers
  1. $to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" ); 
  2. $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here' ) ;
  3. $name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here' ) ; 
  4.  
Basically, the warning is saying that the form was not filled out so there are no values in the $_POST, $_GET or $_COOKIE arrays.
Nov 28 '08 #5
Thank-you so much for your help.
I have used your script but 2 out of 3 have some problems my end.

I have dragged all my script into dreamweaver to allow me to see the colors which are helping me by showing different tags and types.

The $to script I have put in place and commented out my old one.
Sucess, it works great.
I do not get any notices as long as I fill in the email field.

Then I introduced the next script which is the $from script.
This one has caused all code under it including comments to show all in red.

The $name script has the same effect and problem.
Do you need to see what i've done and where I've put all this?
Nov 29 '08 #6
Markus
6,050 Expert 4TB
@stealthmode666
Ah, that's my fault. Sorry. I've mismatched the quotes, so they aren't closing properly.

Here's the last 2 lines revised:
Expand|Select|Wrap|Line Numbers
  1. $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;
  2. $name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ; 
  3.  
I must've been half asleep when I wrote that...

My apologies.

Markus.
Nov 29 '08 #7
I never expected a reply so quickly, so went looking and discovered the single quote instead of double.


Dreamweaver has helped me with the colours in the sense it caused me to investigate why, so down this long and wonderful road I guess I am starting to learn something.

You know I will be back. I will mark this thread as solved.
Nov 29 '08 #8
Markus
6,050 Expert 4TB
@stealthmode666
Aha, well you got it! And good job.


@stealthmode666
Syntax highlighting is one of the beautiful luxuries in life.

@stealthmode666
Great stuff.

See you around,
Markus.
Nov 29 '08 #9
Back again, Still got a page of notices. The last one on the page is the actual field that has not been filled in. I need the user to fill in 2 fields min. then they can hit submit. There are about 100 or so fields and if they don't fill in the 2 required fields or just hit the submit button I'm still getting the page of notices.
As long as the 2 fields are filled in then all is fine.
i just want it to throw an error to tell them to go back and do what was asked as i need the field information
Nov 29 '08 #10
This is one of two scripts i'm using. Both are the same with the data fields in an array and the first script with about 10 fields on the page works no problem. If the user hits the submit it shows the field that needs to be filled in (I display text to tell them to go back and fill-in the required field) without all the notices appearing about undefined indexes.
I don't understand why one works perfectly and the other one shows all the unfilled fields?
Nov 29 '08 #11
Solved the notice:Undefined index in /....... 128
I used .js to insert a space in blank fields left by the user.
Dec 11 '08 #12

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

Similar topics

1
by: Hal Halloway | last post by:
How do I fix this error message below? Thanks. Notice: Undefined index: key_word in C:\Program Files\Apache Group\Apache2\htdocs\search010.php on line 55 .... if( $_GET ) { // line 55 //...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
4
by: iera | last post by:
i've got this message Notice: Undefined index: name in c:\program files\easyphp1-8\www\forum\kemaskini.php on line 2 i've used this coding.. <?php $name = $_POST; $date = $_POST; $time...
2
by: Reggie | last post by:
am trying to create a a upload file.am uploading files ok but i recieve this message. Notice: Undefined variable: uploaded_size in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php on...
3
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if...
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
1
by: francsutherland | last post by:
Notice: Undefined index: send in D:\Domains\workingdata.co.uk\wwwroot\contact_text.php on line 7 Hi, I've started getting this error in the contact page form of my website. The web hosting...
4
by: complearn | last post by:
Do you know why I got these errors for status_bar.php in some webhost, but work perfectly on other webhost? Whats wrong? here are the codes from line 18, our webhost is running php5. ...
2
by: Smellydog | last post by:
I'm having a strange issue with PHP version 5.2.8 running on Windows Vista with Lighttpd. I receive a Notice that says the following: Notice</b>: Undefined index: name in...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.