Page 1 of 1

undefined index:

Posted: Thu May 08, 2003 12:29 am
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:

Posted: Thu May 08, 2003 3:20 am
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+?

??? again

Posted: Thu May 08, 2003 6:59 am
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

Re: ??? again

Posted: Thu May 08, 2003 7:29 am
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

Posted: Thu May 08, 2003 7:37 am
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