473,626 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Undefined index

2 New Member
Hello I have a php contact email form on my a ecommerce shop website !

I am getting a Undefined index error messages coming from the top of the php code, the email form its self works fine,

HERE IS THE ERROR MESSAGES


Notice: Undefined index: Name in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 13

Notice: Undefined index: Tel in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 14

Notice: Undefined index: Email in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 15

Notice: Undefined index: Message in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 16



The code im using is as follows :


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_cache_limiter('none');
  3. session_start();
  4. ob_start();
  5. ?>
  6.  
  7. <?php
  8.  
  9. $EmailFrom = "info@mediadiverse.org.uk";
  10. $EmailTo = "info@mediadiverse.org.uk";
  11. $Subject = "Tools2diy Enquiry";
  12. $Name = Trim(stripslashes($_POST['Name'])); 
  13. $Tel = Trim(stripslashes($_POST['Tel'])); 
  14. $Email = Trim(stripslashes($_POST['Email'])); 
  15. $Message = Trim(stripslashes($_POST['Message'])); 
  16.  
  17. // validation
  18. if (isset($_POST['submit'])) $validate = validateform($Name, $Tel, $Email, $Message);
  19.  
  20. // prepare email body text
  21. $Body = "";
  22. $Body .= "Name: ";
  23. $Body .= $Name;
  24. $Body .= "\n";
  25. $Body .= "Tel: ";
  26. $Body .= $Tel;
  27. $Body .= "\n";
  28. $Body .= "Email: ";
  29. $Body .= $Email;
  30. $Body .= "\n";
  31. $Body .= "Message: ";
  32. $Body .= $Message;
  33. $Body .= "\n";
  34.  
  35. // send email 
  36. if (isset($_POST['submit']) && $validate['false'] != true){
  37.  mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
  38.  $emailsent = true;
  39. }
  40.  
  41. function validateform($Name, $Tel, $Email, $Message){
  42.   //Check empty fields
  43.   if ($Name == ''){
  44.     $return['false'] = true;
  45.     $return['nameblank'] = true;
  46.   }
  47.   if ($Tel == ''){
  48.     $return['false'] = true;
  49.     $return['telblank'] = true;
  50.   }
  51.   if ($Email == ''){
  52.     $return['false'] = true;
  53.     $return['emailblank'] = true;
  54.   }
  55.  
  56.   if ($Message == ''){
  57.     $return['false'] = true;
  58.     $return['messageblank'] = true;
  59.   }
  60.  
  61.   //Check phone number is digits and spaces only
  62.   if (!is_numeric(str_replace(' ','',$Tel))){
  63.    $return['phone'] = true;
  64.    $return['false'] = true;
  65.   }
  66.  
  67.   //Check email is valid
  68.   if (!preg_match('/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/',$Email)){
  69.    $return['email'] = true;
  70.    $return['false'] = true;
  71.   }
  72.  
  73.   //CAPTCHA
  74.   if($_POST['secure'] != $_SESSION['security_number']){
  75.    $return['captcha'] = true;
  76.    $return['false'] = true;
  77.   }
  78.  
  79.   return $return;
  80.  
  81. }
  82. ?>


The strange thing is that im using the exact same code in another site which is hosted on another server ! but its error free and my current hosting have told me its not the hosting so im stuck !

Any help would be great
Jun 7 '10 #1
3 2026
Dormilich
8,658 Recognized Expert Moderator Expert
it just means, those indices are not in the $_POST array, either because there are no $_POST data at all (e.g. no form submitted via POST) or the indices are spelled wrong.
test with var_dump($_POST );
Jun 7 '10 #2
mediator
2 New Member
Hi the form is below ! the form works just cant get rid of the errors




PHP ABOVE HEADER

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $EmailFrom = "info@mediadiverse.org.uk";
  4. $EmailTo = "info@mediadiverse.org.uk";
  5. $Subject = "Tools2diy Enquiry";
  6. $Name = Trim(stripslashes($_POST['Name'])); 
  7. $Tel = Trim(stripslashes($_POST['Tel'])); 
  8. $Email = Trim(stripslashes($_POST['Email'])); 
  9. $Message = Trim(stripslashes($_POST['Message'])); 
  10.  
  11. // validation
  12. if (isset($_POST['submit'])) $validate = validateform($Name, $Tel, $Email, $Message);
  13.  
  14. // prepare email body text
  15. $Body = "";
  16. $Body .= "Name: ";
  17. $Body .= $Name;
  18. $Body .= "\n";
  19. $Body .= "Tel: ";
  20. $Body .= $Tel;
  21. $Body .= "\n";
  22. $Body .= "Email: ";
  23. $Body .= $Email;
  24. $Body .= "\n";
  25. $Body .= "Message: ";
  26. $Body .= $Message;
  27. $Body .= "\n";
  28.  
  29. // send email 
  30. if (isset($_POST['submit']) && $validate['false'] != true){
  31.  mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
  32.  $emailsent = true;
  33. }
  34.  
  35. function validateform($Name, $Tel, $Email, $Message){
  36.   //Check empty fields
  37.   if ($Name == ''){
  38.     $return['false'] = true;
  39.     $return['nameblank'] = true;
  40.   }
  41.   if ($Tel == ''){
  42.     $return['false'] = true;
  43.     $return['telblank'] = true;
  44.   }
  45.   if ($Email == ''){
  46.     $return['false'] = true;
  47.     $return['emailblank'] = true;
  48.   }
  49.  
  50.   if ($Message == ''){
  51.     $return['false'] = true;
  52.     $return['messageblank'] = true;
  53.   }
  54.  
  55.   //Check phone number is digits and spaces only
  56.   if (!is_numeric(str_replace(' ','',$Tel))){
  57.    $return['phone'] = true;
  58.    $return['false'] = true;
  59.   }
  60.  
  61.   //Check email is valid
  62.   if (!preg_match('/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/',$Email)){
  63.    $return['email'] = true;
  64.    $return['false'] = true;
  65.   }
  66.  
  67.   //CAPTCHA
  68.   if($_POST['secure'] != $_SESSION['security_number']){
  69.    $return['captcha'] = true;
  70.    $return['false'] = true;
  71.   }
  72.  
  73.   return $return;
  74.  
  75. }
  76. ?>



BODY CONTENT FORM

Expand|Select|Wrap|Line Numbers
  1. <?php if (isset($emailsent) && ($emailsent == true))
  2.         echo '<p style="text-align: center">Your message has been sent we will be in touch soon!</p>';
  3. ?>
  4.  
  5. <div id="contact-area">
  6.  
  7.                 <form method="post" action="contact.php">
  8.  
  9.                 <div><label for="Name" id="Name">Your name:</label>
  10.                 <input type="text" name="Name" value="<?php if (isset($_POST['Name'])) echo htmlentities($_POST['Name']) ?>"/>
  11.                 <?php if (isset($validate['nameblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
  12.                 </div>
  13.  
  14.                 <div><label for="Tel" id="Tel">Your Tel:</label>
  15.                 <input type="text" name="Tel" value="<?php if (isset($_POST['Tel'])) echo htmlentities($_POST['Tel']) ?>"/>
  16.                 <?php if (isset($validate['telblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
  17.                     <?php if (isset($validate['phone'])) echo '<span class="formerror">Invalid phone number</span>'; ?>
  18.                   </div>
  19.  
  20.                     <div><label for="Email" id="Email">Your email:</label>
  21.                 <input type="text" name="Email" value="<?php if (isset($_POST['Email'])) echo htmlentities($_POST['Email'])?>"/>
  22.                 <?php if (isset($validate['emailblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
  23.                     <?php if (isset($validate['email'])) echo '<span class="formerror">Invalid email address</span>'; ?>
  24.                 </div>
  25.  
  26.                 <div><label for="Message" id="Message">Your message :</label>
  27.                 <textarea name="Message" rows="20" cols="20"><?php if (isset($_POST['Message'])) echo htmlentities($_POST['Message']) ?></textarea>
  28.                 <?php if (isset($validate['messageblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
  29.                 </div>
  30.  
  31.                  <div>
  32.                <label for="captcha" id="captcha">Please answer this </label>
  33.                 <img src="includes/image.php" alt="CAPTCHA" name="captcha" id="captcha"  />
  34.  
  35. </div>
  36.  
  37.  
  38.                 <div><label>Input the answer</label>
  39.                  <input type="text" rows="20" cols="20" name="secure" />
  40.                 <?php if (isset($validate['captcha'])) echo '<span class="formerror">Invalid response</span>'; ?>
  41.                 </div>
  42.  
  43.  
  44.  
  45.                 <div><label><input type="submit" name="submit" value="Submit" class="submit-button" />
  46.                 </label>
  47.                 </div>
  48.             </form>
Jun 7 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
kill the email script, if you don’t find the $_POST variables.
Jun 7 '10 #4

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

Similar topics

1
108830
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still work fine, but with error reporting at all they are marked as errors. Why? What am I doing wrong? www.monkeyclaus.org
5
10883
by: news.bigpond.com | last post by:
getting errors Notice: Undefined index: name in F:\uni\Software engineering\assignment4\guestbook.php on line 6 the variable $name is declared as $name = _POST; What could be causing this? I've recently installed php 5 on IIS with mysql 4. All running on windows XP
4
7179
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: Undefined index: city in /home/www/reformcagunlaws.com/new.php on line 8 PHP Notice: Undefined index: county in /home/www/reformcagunlaws.com/new.php on line 9 PHP Notice: Undefined index: zip in /home/www/reformcagunlaws.com/new.php on line...
3
4960
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined index: abdatum in /zipcode.php on line 13 Notice: Undefined index: zimmer in /zipcode.php on line 14 Notice: Undefined index: city in /zipcode.php on line 39 Notice: Undefined index: state in /zipcode.php on line 41
3
5492
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: Undefined index: FriendName in D:\Yan\Over_8\SendEmail.php on line 4, Notice: Undefined index: FriendEmail in D:\Yan\Over_8\SendEmail.php on line 5, Notice: Undefined index: Name in D:\Yan\Over_8\SendEmail.php on line 6, Notice: Undefined index: Email...
15
4460
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about enased whitespace (to my best memory) AT other times I get an undefined index notice as below: Notice: Undefined index: last_reminder_id in...
5
7178
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my local server it was working fine but giving some errors those are Notice: Undefined index: phplogin in C:\Inetpub\wwwroot\sampleft\index.php on line 116 Notice: Undefined variable: username in C:\Inetpub\wwwroot\sampleft\index.php on line 116 ...
3
3865
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 (empty($info)) { $info='noinfo'; } changeinfo($info); Hey everyone, I keep getting an error regarding the above code. These are the errors: Notice: Undefined index: channels in /home/forcefed/public_html/index.php on line 5
5
7356
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 : $http_ref= $HTTP_REFERER; $prog = $_COOKIE;
3
5991
by: razvanel442 | last post by:
Hi all i am new here! I take a look on forum but i don't found a the answer for my problem ok this is my problem: Line47:$user = $_GET; Line48:$pass = $_GET; Line49:$char = $_GET;
0
8265
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
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
8637
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...
1
8364
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
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
4092
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
2625
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

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.