954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php notice : undefined index

i am getting this error

Notice: Undefined index: firstName in C:\xampp\htdocs\flasblog\test.php on line 3

Notice: Undefined index: lastName in C:\xampp\htdocs\flasblog\test.php on line 3

here is my php code

<?php include_once"scripts/connect.php"; ?>
<?php
$text=$_POST['firstName']." ".$_POST['lastName'];
$to="anubhavjhalani09@gmail.com";
$subject="Message from php";



//data insert into database
$sql="INSERT INTO entries (contents)
VALUES
('$text')";

echo $text;
?>


please somebody help me !!!!!!!!! i know how to hide this error but its not the solution of this problem.i am getting the variables from a flash file which is in the same folder.

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

Add this to the start of your code:

echo "Post:".print_r($_POST,true);
echo "Get: ".print_r($_GET,true);


This should give you an idea of what Flash is passing to your script.

madCoder
Junior Poster
145 posts since Feb 2010
Reputation Points: 21
Solved Threads: 37
 

thanx for the reply
now i am getting this


Post:Array ( ) Get: Array ( )
Notice: Undefined index: firstName in C:\xampp\htdocs\flasblog\test.php on line 5

Notice: Undefined index: lastName in C:\xampp\htdocs\flasblog\test.php on line 5

my php script is

<?php include_once"scripts/connect.php"; ?>
<?php
    echo "Post:".print_r($_POST,true);
    echo "Get: ".print_r($_GET,true);
$text=$_POST['firstName']." ".$_POST['lastName'];
$to="anubhavjhalani09@gmail.com";
$subject="Message from php";



//data insert into database
$sql="INSERT INTO entries (contents)
VALUES
('$text')";

echo $text;
?>


now what does it mean ??

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

Is this happening AFTER you submit the Flash form? If you were to call test.php directly you would expect to get those warnings since nothing was passed to it via get or post.

If so, it doesn't look like the flash form is passing anything to test.php on submit.

madCoder
Junior Poster
145 posts since Feb 2010
Reputation Points: 21
Solved Threads: 37
 

Try this:

if(isset($_POST['firstName'] && $_POST['lastName'])) {
$text=$_POST['firstName']." ".$_POST['lastName'];
$to="anubhavjhalani09@gmail.com";
$subject="Message from php";



//data insert into database
$sql="INSERT INTO entries (contents)
VALUES
('$text')";

echo $text;
}
Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

heyy i just play my flash movie and then i check the test.php page on browser and then i am getting this error .is this the right way to send variables to php by just playing the flash movie?????my fla , swf and php file is in the same folder

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

@zero13
i tried your code . now i m getting this error

Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in C:\xampp\htdocs\flasblog\test.php on line 3

my php code is

<?php include_once"scripts/connect.php"; ?>
<?php
        if(isset($_POST['firstName'] && $_POST['lastName'])) {
    $text=$_POST['firstName']." ".$_POST['lastName'];
    $to="anubhavjhalani09@gmail.com";
    $subject="Message from php";
     
     
     
    //data insert into database
    $sql="INSERT INTO entries (contents)
    VALUES
    ('$text')";
     
    echo $text;
    }
?>


now what to do ??? and also look at my question above

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 
heyy i just play my flash movie and then i check the test.php page on browser and then i am getting this error .is this the right way to send variables to php by just playing the flash movie?????my fla , swf and php file is in the same folder

No. You don't play a flash movie and thenvisit another page. A form, be it from html or flash, must be submitted and pass information to a script. The POST is passed within the request the browser makes to the web server when calling the form handler.

madCoder
Junior Poster
145 posts since Feb 2010
Reputation Points: 21
Solved Threads: 37
 
No. You don't play a flash movie and then visit another page. A form, be it from html or flash, must be submitted and pass information to a script. The POST is passed within the request the browser makes to the web server when calling the form handler.



please write your answer in simple english . i am not a native english speaker

aaloo
Junior Poster in Training
76 posts since Oct 2011
Reputation Points: 22
Solved Threads: 0
 

@zero13 i tried your code . now i m getting this error

Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in C:\xampp\htdocs\flasblog\test.php on line 3

my php code is

<?php include_once"scripts/connect.php"; ?>
<?php
        if(isset($_POST['firstName'] && $_POST['lastName'])) {
    $text=$_POST['firstName']." ".$_POST['lastName'];
    $to="anubhavjhalani09@gmail.com";
    $subject="Message from php";
     
     
     
    //data insert into database
    $sql="INSERT INTO entries (contents)
    VALUES
    ('$text')";
     
    echo $text;
    }
?>

now what to do ??? and also look at my question above

<?php
include_once"scripts/connect.php";
if(isset($_POST['firstName']) && isset($_POST['lastName'])) {
    $text=$_POST['firstName']." ".$_POST['lastName'];
    $text = str_replace("'",'& # 3 9 ;',$text);//ascii code for a quote
    $to="anubhavjhalani09@gmail.com";
    $subject="Message from php";
         
    //data insert into database
    $sql="INSERT INTO entries (contents) VALUES ('$text')";
     
    echo $text;
}else{
    echo 'not set';
}
?>
Biiim
Posting Whiz
387 posts since Oct 2011
Reputation Points: 93
Solved Threads: 55
 
heyy i just play my flash movie and then i check the test.php page on browser and then i am getting this error .is this the right way to send variables to php by just playing the flash movie?????my fla , swf and php file is in the same folder

Yeah, when you submit a form it sends the contents you type in via POST variables, your form is expecting them to run (isset($_POST['firstName'])) without them (navigating to it in a browser) it doesn't have the data so should just ignore the request eg. echo 'not set';

the undefined index notice is just telling you them post variables are not there, isset checks if they are first so it doesn't give a notice and you can tell it to do something else if they arn't

Biiim
Posting Whiz
387 posts since Oct 2011
Reputation Points: 93
Solved Threads: 55
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: