Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 107,638 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 980 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Undefined Inedx: variable name

 
Reply to this topicStart new topic

Undefined Inedx: variable name

deepman007
post 29 Jun, 2008 - 01:01 PM
Post #1


New D.I.C Head

*
Joined: 28 May, 2008
Posts: 13

I created an check.php page that takes in users E-maill address.

CODE


  <form action="check.php" method="post" >
              <input  type="text" name="email"  size="10" />
              <input  type="submit" value="submit" />
        </form>

On the same page, I want to store it into the database


CODE


<?php
         $email=mysql_real_escape_string($_POST["email"]);
              echo "<center>$email</center>";
         $shop->db->check_email($email);
  $insert = "INSERT INTO tbl_subscribe (cst_submail) VALUES ('$email')";
    $result = $shop->db->executeQuery($insert, "result");    
        
       ?>

and the ERROR is "Notice: Undefined index: email in C:\wamp\www\newer\check.php on line 60 "

The link 60 is: $email=mysql_real_escape_string($_POST["email"]);

Does anyone know why I got the undefined index?
User is offlineProfile CardPM

Go to the top of the page


joeyadms
post 29 Jun, 2008 - 04:04 PM
Post #2


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600
My Contributions


this probably happens before you submit the page, what you want to do is check to see if the form was submitted first.
CODE

if(!is_null($_POST['email)) {
// form has been submitted , add to database

}



Oh and props on escaping with real_escape_string smile.gif
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 29 Jun, 2008 - 04:12 PM
Post #3


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 377



Thanked 16 times

Dream Kudos: 350
My Contributions


or you could use isset
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 29 Jun, 2008 - 04:31 PM
Post #4


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600
My Contributions


or you could die!!!!

jk

^ Thats what i was trying to think of, but im a little inebriated.
User is offlineProfile CardPM

Go to the top of the page

deepman007
post 30 Jun, 2008 - 10:25 AM
Post #5


New D.I.C Head

*
Joined: 28 May, 2008
Posts: 13

so my logic will be If the $_POST['email'] is equal to null or empty, then prompt a message saying please enter an e-mail address else check to see if the email address exits and then store into the DB ?


CODE

  if($_POST['email'] ==""){
   echo"Please type in an E-mail address"
}else{

  
         $email=mysql_real_escape_string($_POST["email"]);
         echo "<center>$email</center>";
         $shop->db->check_email($email);
         $insert = "INSERT INTO tbl_subscribe (cst_submail) VALUES ('$email')";
         $result = $shop->db->executeQuery($insert, "result");    
        
}


Why is my <?php include("footer.php") ?> not showing up in the page?

This post has been edited by deepman007: 30 Jun, 2008 - 10:30 AM
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 30 Jun, 2008 - 11:12 AM
Post #6


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600
My Contributions


If you done it that way then even if someone just viewed the page for the first time, this is how it should look

CODE

<?php

if(isset($_POST['email'])):
    $email = mysql_real_escape_string($_POST['email']);
    echo "<center>$email</center>";
    $shop->db->check_email($email);
    $insert = "INSERT INTO tbl_subscribe (cst_submail) VALUES ('$email')";
    $result = $shop->db->executeQuery($insert, "result");  
    else :
?>
        
<form action='' method='post'>
    <input type='text' name='email' size='10'/>
    <input type='submit' value='submit'/>
</form>

<?php endif; ?>



But ideally you would do this

1. Check to make sure $_POST['email'] is set
2. Make sure $_POST['email'] is a valid email address.
A) If it is a valid address, then add to db and show confirmation
message or whatever.
cool.gif If it was not a valid email address, set a variable
$error = 'Invalid email address';
User is offlineProfile CardPM

Go to the top of the page

akozlik
post 30 Jun, 2008 - 11:14 AM
Post #7


D.I.C Regular

Group Icon
Joined: 25 Feb, 2008
Posts: 395



Thanked 15 times

Dream Kudos: 700
My Contributions


Make sure you echo out the value of $_POST['email'] while you're searching down your problem, but the code you have looks pretty good.

Do you have the footer.php file in the same directory as the one calling it?
User is offlineProfile CardPM

Go to the top of the page

deepman007
post 30 Jun, 2008 - 01:19 PM
Post #8


New D.I.C Head

*
Joined: 28 May, 2008
Posts: 13

Yea I have the footer.php in the same directory as in the check.php . During the checking of the validation of the E-mail address, if certain condition is meet, then prompts an message.

CODE

if(){
  die("Please type in a correct E-mail address");
}
if(){
  die("Your E-mail does not exists");
}


I guess the Die function terminates the script, but why <?php include("footer.php"); ?> did not run when its not even in the check_email() function ?
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 06:22PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month