undefined index:

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

undefined index:

Post by harsha »

hi
all

Recently i discovered a problem!!!

i am using php 4.30 v and in my code i am getting this error

undefined index: to 'fname'

the fname is the form variable and i am not able to insert the data in the
variable in to database as it is showing this error i used lower version and it is working fine.

can i know why this error undefined index: comes

i tried with error_repoting(0) and others but i am not satisfied i am more intrested in why that error come i want the exact reason can any one
tell me the reason

i am eagerly waiting for the reply .
:x :roll:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

this happens if your script tries to access an array element that is not set, e.g.

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

$arr = array('a'=>'A', 'c'=>'C');
$t = $arr['b'];

?>
How do you pass the parameters and did you read Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+?
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

??? again

Post by harsha »

the fname is the form variable it is set in the
$_POST['fname']

so how can this possible.

i feel that all the form variable values are stored in
$_POST[''] array and

<form method="POST" action="$PHP_SELF">
<input type="text" name="fname">
....
.....................</form>

in the above form the fname is set in the $_POST[] Array and

i tried to insert $_POST['fname'] in to the database

line 11: $sql="INSERT INTO candid(cname) values($_POST['fname'])";

php is returning this error:
undefined index: to 'fname' on line 11

and Mr. volka

i am not satisfied with your answer i want still more convincing answer.

thanx
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: ??? again

Post by twigletmac »

harsha wrote:and Mr. volka

i am not satisfied with your answer i want still more convincing answer.

thanx
If you're going to be blatantly rude to those trying to help you you are unlikely to get many more responses to your query - the polite thing to say would be:
"Thank you for your help, unfortunately this has not allowed me to solve the problem - do you have any other suggestions for me? I have posted the code I am using below as this may help you understand what I am trying to do. Apologies for not posting this earlier."

BTW, I am not satisfied with your question, I still want a better thought out and clearer one.
http://www.catb.org/~esr/faqs/smart-questions.html

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Volker is my given name. You may adress me as Mr.Krause if you want to but I'd like it to keep informal here ;)
Could tell you "don't worry, it'll work fine even with this notice just decrease the reporting level" if this was more convenient esp. since I gave "you will find it more satisfactory to find out yourself" a thought but just try

Code: Select all

$sql="INSERT INTO candid(cname) values($_POST[fname])";
within string literals you don't need to mark another literal like fname. In fact I was astonished to see php didn't return a compile error 8O
Post Reply