You are here: Re: Problem with a script « PHP Programming Language « IT news, forums, messages
Re: Problem with a script

Posted by Jerim79 on 04/12/07 17:28

On Apr 10, 11:52 am, Rami Elomaa <rami.elo...@gmail.com> wrote:
> Jerim79 kirjoitti:
>
> > Here it is:
>
> > <?php
>
> ...A few hundred lines of code snipped...
>
>
>
>
>
> > I tried formatting it for easy viewing, don't know if I succeeded. A
> > brief explanation is in order. The first page of the form asks a user
> > for a number and their email address. The number and email address are
> > passed to the second page of the form, which is the script listed
> > above. First thing we do is declare local variables. Next, we check
> > for any empty variables. If there are, $error>0 and we display the
> > form. If $error<=0, we call the submit.php page which writes
> > everything to the database.
>
> > The FOR loop in the middle determines if a customer entered a number
> > on the previous page. If there is a number, then it executes the next
> > block of code. If not, we skip this section. This way, if the customer
> > enters 0 or nothing for the number on the first page, then we don't
> > clutter up the screen with those questions. The WHILE loop right below
> > there, repeats certain questions for the number of times the user
> > entered on the first page. So there is a set of questions that is
> > asked once of all users, and a set of questions that is asked a number
> > of times, depending on what number the customer entered. The form
> > repeats the questions the correct number of times.
>
> > I am trying to accomplish some form of data verification. For the
> > first set of question, data verification works correctly, by not
> > allowing you to move further until every question is answered.
> > However, it automatically displays the error messages when the page
> > loads. I can't use an inline if($_SERVER['REQUEST_METHOD']=='POST')
> > { echo $msg[i]; } method, since the form is always posted. Inside of
> > the WHILE loop, I can only get it to verify $Variable9. It doesn't
> > even check the other fields . Since the same question may be asked 10
> > times, I need to specify which occurrence of the question was not
> > answered. That is why I use the FOR loop.
>
> > If you know of a way to make the current code work, or if you have a
> > better idea of how to do this from top to bottom, please let me know.
> > I would like to also be able to carry over the user's selections, so
> > that they don't have to recheck each box, if they only left off one.
>
> 1) You really really need to learn how to use loops. Copy&pasting the
> same code 10 times is insane.
>
> For example:
> if (empty($Variable1)){
> $msg1=" * You have not answered this question.";
> $error++;}
>
> if (empty($Variable2)){
> $msg2=" * You have not answered this question.";
> $error++;}
>
> if (empty($Variable3)){
> $msg3=" * You have not answered this question.";
> $error++;
>
> } ........ the same thing over and over again, why not just use a loop?
>
> This becomes one simple loop easily, but you might want to use an array
> in that case:
>
> for($i=1;$i<=8;$i++){
> if (empty($Variable[$i])){
> $msg[$i]=" * You have not answered this question.";
> $error++;
> }
>
> }
>
> 2) TLDR, Too Long, Didn't Read. Post a conciderably shorter code sample
> and someone might actually get intrested in it. Pasting 1000 lines of
> codes makes you look like you have no idea what the problem is and how
> to start fixing it. Instead, post only the piece of code that matters.
> I'm not gonna dig thru all that spaghetti trying to find the problem,
> and I think most people here wouldn't either...
>
> --
> Rami.Elo...@gmail.com
> "Olemme apinoiden planeetalla."

Who ever said I don't know how to use loops? I use loops throughout
the code. I know this concept is hard for you to grasp, but I don't
actually name all my variables $VariableX. I have unique names for
them. I obviously changed the names, because I don't want anyone
recognizing the script or where it is from. But yeah, you're right,
better to just assume I am retarded.

Funny how you say it is too long, yet someone else has already posted
a reply elsewhere. A meaningful reply, will actual help. If it was too
long that you didn't read it, then perhaps you shouldn't post a reply,
since not having read it, you can't really give an informed opinion.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация