RE: [PHP-DB] Re: Undefined index and variables
| From: | Ben Joyce | Date: | Wed, 15 Jan 2003 16:49:14 +0000 |
| Subject: | RE: [PHP-DB] Re: Undefined index and variables | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-24881@lists.php.net to get a copy of this message | ||
Couldn't you use the 'for each' method on $_POST instead?
.b
> -----Original Message-----
> From: Hutchins, Richard [mailto:Richard.Hutchins@GetingeCastle.com]
> Sent: 15 January 2003 16:44
> To: 'Fred Wright'; php-db@lists.php.net
> Subject: RE: [PHP-DB] Re: Undefined index and variables
>
>
> Fred,
>
> I don't have much time today, but here is my initial
> assessment of what might be going wrong with your page:
>
> You display add.php which draws a form for data.
> You submit that form to add.php (itself).
> The form redraws inside the page.
> You get errors when add.php looks for data in the
> $HTTP_POST_VARS array because the page is fresh and that
> array is empty.
>
> Problem is that there is no code to handle the data that was
> entered in the first place. Once you hit submit, the add.php
> page is (re)drawn in its original state - with no values in
> the fields. Therefore, when the $_POST['varname'] statement
> looks in $HTTP_POST_VARS, there's nothing to display so you
> get the Undefined Index errors. It's almost like refreshing the page.
>
> My advice would be to separate the code for the data entry
> and data handling parts of your project into independent
> scripts. Use add.php to collect the data then send the data
> to a php script called handleAdd.php that gets the name/value
> pairs and submits them to the database. After submitting the
> data to the database in handleAdd.php, forward the user back
> to another page (add.php again, if you want) where they can
> get some kind of confirmation the data was entered.
>
> A further recommendation would be to provide the list with
> the code you gave to me so maybe somebody else with a little
> more free time might be able to assist you further. Sorry I
> couldn't provide any more help.
>
> Rich
>
> > -----Original Message-----
> > From: Fred Wright [mailto:to_637fjw@hotmail.com]
> > Sent: Wednesday, January 15, 2003 12:21 PM
> > To: php-db@lists.php.net
> > Subject: [PHP-DB] Re: Undefined index and variables
> >
> >
> > <?
> > //This is lines 22 and 23 of Add.php
> > require("common.php") ;
> > GenerateHTMLForm();
> > $smt2= $_POST['Ref']; //line 22
> > $smt3=$_POST['Chassis']; //line 23
> >
> > The form below is in common.php
> >
> > function GenerateHTMLForm() {
> >
> > printf("<FORM action=\"add.php\" METHOD=post>");
> >
> > printf("<TABLE border=\"0\" width=\"100%%\">");
> >
> > printf("<TR><TD>Reference:</TD>");
> > printf("<TD><INPUT TYPE=text SIZE=5
> > NAME=Ref></TD></TR>");
> >
> > printf("<TR><TD>Chassis:</TD>");
> > printf("<TD><INPUT TYPE=text SIZE=25 NAME=Chassis
> > ></TD></TR>");
> > printf("</TABLE>"); printf("<INPUT TYPE=submit
> > name=\"submit\">");
> > printf("</FORM>" );
> > }
> >
> > "Fred Wright" <to_637fjw@hotmail.com> wrote in message
> > news:20030115105508.13458.qmail@pb1.pair.com...
> > > Hi to all
> > > Being new to PHP I am naturally experiencing some minor problems.
> > >
> > > I have a form which processes Ref and Chassis data, when I
> > load Add.php
> > > which does work but on loading get errors
> > >
> > > Notice: Undefined index: Ref in C:\Xitami\webpages\add.php
> > on line 22
> > > Notice: Undefined index: Chassis in
> > C:\Xitami\webpages\add.php on line 23
> > > How do I get rid of these undefined errors? Could anyone
> > advise please.
> > > Regards
> > > Fred
> > >
> > > printf("<FORM action=\"add.php\" METHOD=post>");
> > >
> > > printf("<TABLE border=\"0\" width=\"100%%\">");
> > >
> > > printf("<TR><TD>Reference:</TD>");
> > >
> > > printf("<TD><INPUT TYPE=text SIZE=5 NAME=Ref
> > > ></TD></TR>");
> > >
> > > printf("<TR><TD>Chassis:</TD>");
> > > printf("<TD><INPUT TYPE=text SIZE=25 NAME=Chassis
> > > ></TD></TR>");
> > >
> > > printf("</TABLE>");
> > >
> > > printf("<INPUT TYPE=submit name=\"submit\">");
> > >
> > > printf("</FORM>" );
> > >
> > >
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>