|
-
June 1st, 2012, 03:59 PM
#1
Undefined Index name
Hello everyone
I'm learning PHP because I want to develop some websites and have I set up web development environment.
I am using XAMPP + YII + Eclipse PHP IDE
Everything works perfectly but I was following a guide and eventhough I followed step by step, I'm getting an error that isn't supposed to be there.
Code:
<!DOCTYPE HTML>
<html>
<link rel="stylesheet" type="text/css" href="css/main.css">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Contact Form</title>
</head>
<body>
<header class="body">
</header>
<section class="body">
<?php
$name = $_POST['name']; <!-- This is where I get the error undefined index name?>
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: DEMO';
$to = '[email protected]';
$subject = 'Hello';
?>
<form method="post" action="index.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</section>
<footer class="body">
</footer>
</body>
</html>
I am getting the error in the php script that I've embedded inside the index.php file, so yeah the html and php code are in the same index.php file , that's why the form is pointing to the same file.
Any help will be appreciated. Thank you
-
June 1st, 2012, 04:14 PM
#2
Re: Undefined Index name
Unless the page is being loaded from the form actually being posted, then there is no post data. So, to keep the actual form processing code from loading when the page isn't posting data, you simple make sure the variables are being set.
PHP Code:
<?php if (isset($_POST['name'])) { $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: DEMO'; $to = '[email protected]'; $subject = 'Hello'; } ?>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 10th, 2012, 07:06 PM
#3
Re: Undefined Index name
Thank you for the reply, so basically the isset function checks wether the box name is filled or not right?
I want to try to send an email to me but I'm doing this work offline, what I mean is that I'm using offline server to test my website (on XAMPP) - can I send email offline or I must upload my code on an online server?
-
June 10th, 2012, 09:56 PM
#4
Re: Undefined Index name
isset() simply detects if a variable has been created or not.
To send mail, your PHP configuration must have access to a mail server. If you don't...you cannot send mail.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 11th, 2012, 03:02 PM
#5
Re: Undefined Index name
so is it there anyway to have access to the mail server when developing in localhost ?
-
June 11th, 2012, 03:52 PM
#6
Re: Undefined Index name
Download a copy of Mercury Mail Server and then make sure your PHP configuration file is setup for SMTP output.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 12th, 2012, 07:02 AM
#7
Re: Undefined Index name
Thank you
I will try this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|