Undefined Index

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Reference the above  thread:   "Passing a HTML variable to a  PHP file  
using include". One thing I've learned  over the years is  that an error  
doesn't always come from where the compiler/interperture says it does.  
Case  in point  maybe.

I am getting this error:

Notice: Undefined index: var1 in  
/var/www/vhosts/texasflyfishers.org/httpdocs/form.php on line 4

Warning: fwrite(): supplied argument is not a valid stream resource in  
/var/www/vhosts/texasflyfishers.org/httpdocs/form.php on line 5

Warning: fclose(): supplied argument is not a valid stream resource in  
/var/www/vhosts/texasflyfishers.org/httpdocs/form.php on line 6

in this function:

if($_GET["op"] == "ds") {
   foreach ($_GET["name"] as $key=>$value) {
     fwrite($fp,$_GET["name"][$key] ."&nbsp;". $_GET["email"][$key]  
."&nbsp;". $_GET["phone"][$key] ."&nbsp;". $_GET["id"][$key]);

'var1' comes from this last line in this snippet in a previous function:

<?php include ($_GET["var2"]); ?> // this works
<br clear="all">
<?php include ($_GET["var1"]); ?> //this works
<form action="form.php?var1=>($_GET["var1"])" method="GET"> //  NOT

I  have found that the text editor you are using will  color out the  
parts of code if they are correct. This code does not color out  evenly.
In the 2 'include' statements '$_GET' is red.  In the 'form action'  
statement it is not.

At this   point 'var1' is a  name on a disk with zero length. Is it  
possible that the error trapping of the 'include' function is taking  
care of this and the error trapping of the 'fopen' alerts you that it is  
going to crash fwrite because 'var1' is now corrupted?

I'm clueless, can anyone help?

Re: Undefined Index

Quoted text here. Click to load it

Since the form method is GET, it will replace any existing get parameters in  
the form action. Use a hidden field in the form instead:

<input type="hidden" name="var1" value="<?php echo $_GET["var1"] ?>">

Dunno what the heck this var1=>($_GET["var1"]) syntax is, smarty perhaps, I  
don't know cos I've never used it, but I assume you understand my example  
and can adjust it to meet your requirments..

Get parameters in form action work only if the form method is POST...

"Ohjelmoija  on  organismi  joka  muuttaa  kofeiinia  koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pivittyv nettisarjis
spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)  

Site Timeline