Entry
PHP: Error: 'Undefined variable' [undefined index]
Jul 3rd, 2005 00:33
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 06 April 2005 - 09:04 pm ----------------------
PHP: Error: 'Undefined variable' [undefined index]
---
---
Error: 'Undefined variable'
---
---
* Possible cause: Not initializing your variables via $_REQUEST, $_GET
or $_POST
---
Possible solution:
---
Initialize the variables via
$<your variablename> = $_REQUEST['<your variablename>'];
---
(or similar, but less general:
$<your variablename> = $_GET['<your variablename>'];
or
$<your variablename> = $_POST['<your variablename>'];
---
e.g.
--- cut here: begin --------------------------------------------------
<?php
$myvariable1 = $_REQUEST['myvariable1'];
?>
--- cut here: end ----------------------------------------------------
---
---
e.g.
--- cut here: begin --------------------------------------------------
<?php
$myvariable1 = $_REQUEST['myvariable1'];
$myvariable2 = $_REQUEST['myvariable2'];
?>
--- cut here: end ----------------------------------------------------
---
---
Error: 'Undefined index'
---
---
* Possible cause: Some form elements on your HTML form (e.g. anchors
<A>) did not contain any information (are empty).
---
e.g.
Input boxes (<INPUT>) are filled in with text by the user, but URLs
(<A>) usually not (in HTML pages).
---
e.g.
--- cut here: begin --------------------------------------------------
<INPUT
...
>
--- cut here: end ----------------------------------------------------
works OK, but doing the same with
--- cut here: begin --------------------------------------------------
<A
...
>
--- cut here: end ----------------------------------------------------
gives (also) this error.
---
Possible solution:
Use <INPUT> or <SELECT> form fields in your HTML page
(instead of e.g. anchors <A>)
---
---
Tested successfully on
Microsoft Windows XP Professional (service pack 2),
running
-PHP v5
-Apache v2.0
-MySql v4.1
---
---
Internet: see also:
---
[Internet: source: http://www.google.com search for ''undefined
variable' PHP ': http://www.dmcinsights.com/phorum/read.php?
5,15080,15088]
---
Undefined variable
http://www.faqts.com/knowledge_base/view.phtml/aid/14093
---
PHP: Error reporting
http://www.php.net/error_reporting
---
---
Keyar Srinivasan
---
Try using isset Function b4 assigning the $_REQUEST or $_POST or
$_GET.,
The example is as follows
if(isset($_POST['<your posted variable name>'])
$YourVariable = $_POST['<your posted variable name>'];
I hope this will solve and can not be used for $_REQUEST or $_GET etc.
----------------------------------------------------------------------