Problem with a script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerim79

    Problem with a script

    Here it is:

    <?php

    if($_SERVER['REQUEST_METHOD ']=='POST'){

    $Number=$_POST['Number'];
    $Email=$_POST['Email'];
    $Number2=0;
    $error=0;

    $Variable1=$_PO ST['Variable1'];
    $Variable2=$_PO ST['Variable2'];
    $Variable3=$_PO ST['Variable3'];
    $Variable4=$_PO ST['SVariable4'];
    $Variable5=$_PO ST['Variable5'];
    $Variable6=$_PO ST['Variable6'];
    $Variable7=$_PO ST['IVariable7'];
    $Variable8=$_PO ST['Variable8'];
    $Check=$_POST['Check']; //We will use this to determine if we
    should do data checks

    if (empty($Variabl e1)){
    $msg1=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e2)){
    $msg2=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e3)){
    $msg3=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e4)){
    $msg4=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e5)){
    $msg5=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e6)){
    $msg6=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e7)){
    $msg7=" * You have not answered this question.";
    $error++;
    }

    $Variable9=$_PO ST['Variable9'];
    $Variable10=$_P OST['Variable10'];
    $Variable11=$_P OST['Variable11'];
    $Variable12=$_P OST['Variable12'];
    $Variable13=$_P OST['Variable13'];
    $Variable14=$_P OST['Variable14'];
    $Variable15=$_P OST['Variable15'];
    $Variable16=$_P OST['Variable16'];
    $Variable17=$_P OST['Variable17'];


    for ($i=0; $i<$Number; $i++){
    if (empty($Variabl e9[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e10[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e11[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e12[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e13[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e14[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e15[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e16[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e17[$i])){
    $msg[i]=" * You have not answered this question.";
    $error++;
    }
    } //closes FOR loop



    if ($error>0){
    echo "<form action=\"survey .php\" method=\"POST\" >
    <input type=\"hidden\" name=\"Email\" value=\"$Email\ " />
    <input name=\"Number\" type=\"hidden\" value=\" $Number\" />
    <table width=\"700\" border=\"0\" cellpadding=\"0 \" align=\"center
    \">
    <tr><td colspan=\"25\"> <strong><center >PART 1 - SURVEY</center></
    strong<br/></td></tr>
    <tr><td align=\"right\" ></tr>
    <tr><td align=\"right\" ></td></tr>
    <tr><td colspan=\"25\"> Please answser the following questions:<br/
    ><br/></td </tr>
    <tr><td colspan=\"25\" bgcolor=\"#CCCC CC\">1. Question 1?</
    td </tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 1\" type=\"radio\" value=
    \"Excellent\ " /Excellent</td>
    <td align=\"center\ "><input name=\"Variable 1\" type=\"radio\" value=
    \"Good\" /Good</td>
    <td align=\"center\ "><input name=\"Variable 1\" type=\"radio\" value=
    \"Average\" /Average</td>
    <td align=\"center\ "><input name=\"Variable 1\" type=\"radio\" value=
    \"Poor\" /Poor</td>
    <td colspan=\"21\"> $msg1</td></tr>
    <tr><td colspan=\"25\" bgcolor=\"#CCCC CC\">2. Question 2?</td></tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 2\" type=\"radio\" value=
    \"Excellent\ " /Excellent</td>
    <td align=\"center\ "><input name=\"Variable 2\" type=\"radio\" value=
    \"Good\" /Good</td>
    <td align=\"center\ "><input name=\"Variable 2\" type=\"radio\" value=
    \"Average\" /Average</td>
    <td align=\"center\ "><input name=\"Variable 2\" type=\"radio\" value=
    \"Poor\" /Poor</td>
    <td colspan=\"21\"> $msg2</td></tr>
    <tr><td colspan=\"25\" bgcolor=\"#CCCC CC\">3. Question 3?</td></tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 3\" type=\"radio\" value=
    \"Excellent\ " /Excellent</td>
    <td align=\"center\ "<input name=\"Variable 3\"type=\"radio \" value=
    \"Good\" /Good</td>
    <td align=\"center\ "><input name=\"Variable 3\" type=\"radio\" value=
    \"Average\" /Average</td>
    <td align=\"center\ "><input name=\"Variable 3\" type=\"radio\" value=
    \"Poor\" /Poor</td>
    <td colspan=\"21\"> $Variety</td>
    </tr>
    <tr><td colspan=\"25\" bgcolor=\"#CCCC CC\">4. Question 4?</td></
    tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 4\" type=\"radio\" value=
    \"Excellent\ " /Excellent</td>
    <td align=\"center\ "><input name=\"Variable 4\" type=\"radio\" value=
    \"Good\" /Good</td>
    <td align=\"center\ "<input name=\"Variable 4\" type=\"radio\" value=
    \"Average\" /Average</td>
    <td align=\"center\ "><input name=\"Variable 4\" type=\"radio\" value=
    \"Poor\" /Poor</td>
    <td colspan=\"21\"> $msg4</td>
    </tr>
    <tr><td colspan=\"25\" bgcolor=\"#CCCC CC\">5. Question 5?</td></tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 5\" type=\"radio\" value=
    \"Excellent\ " /Excellent</td>
    <td align=\"center\ "><input name=\"Variable 5\" type=\"radio\" value=
    \"Good\" /Good</td>
    <td align=\"center\ "><input name=\"Variable 5\" type=\"radio\" value=
    \"Average\" /Average</td>
    <td align=\"center\ "<input name=\"Variable 5\" type=\"radio\" value=
    \"Poor\" /Poor</td>
    <td colspan=\"21\"$ msg5</td>
    </tr>
    <tr>
    <td colspan=\"25\" bgcolor=\"#CCCC CC\">6. Question 6?</td>
    </tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 6\" type=\"radio\" value=
    \"Excellent\ " /Excellent</td>
    <td align=\"center\ "<input name=\"Variable 6\" type=\"radio\" value=
    \"Good\" /Good</td>
    <td align=\"center\ "><input name=\"Variable 6\" type=\"radio\" Value=
    \"Average\"/Average</td>
    <td align=\"center\ "><input name=\"Variable 6\" type=\"radio\" value=
    \"Poor\" /Poor</td>
    <td colspan=\"21\"> $msg6</td>
    </tr>
    <tr>
    <td colspan=\"25\" bgcolor=\"#CCCC CC\">7. Question 7?</td></tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 7\" type=\"radio\" value=
    \"Excellent\ " /Excellent</td>
    <td align=\"center\ "><input name=\"Variable 7\" type=\"radio\" value=
    \"Good\" /Good</td>
    <td align=\"center\ "><input name=\"Variable 7\" type=\"radio\" value=
    \"Average\" /Average</td>
    <td align=\"center\ "<input name=\"Variable 7\" type=\"radio\" value=
    \"Poor\" /Poor</td>
    <td colspan=\"21\"> $msg7</td>
    </tr>
    </table>
    <br/
    >&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;AD DITIONAL
    COMMENTS: <br/><div align=\"center\ "><textarea name=\"Variable 8\" cols=
    \"83\" rows=\"10\"></textarea></div><div align=\"center\ "><br/>
    <br/>
    <strong>
    <center>";

    if ($Number>0){
    echo "<table width=\"700\" border=\"0\" cellpadding=\"5 \">
    <tr><td colspan=\"10\"> <strong><center >PART 2 - SURVEY
    </center</strong></td></tr><tr><td colspan=\"10\"> &nbsp;</td></tr>
    <tr><td colspan=\"10\"> <div align=\"center\ ">Please fill out
    each section below. </div></td></tr></table><br/></center></strong>";
    $SeminarNumber= 1;

    while ($Number2<$Numb er){
    echo "<table width=\"700\" border=\"0\" cellpadding=\"0 \" align=
    \"center\">
    <tr><td colspan=\"60\" align=\"center\ "><strong>Semin ar
    Number
    $SeminarNumber</strong></td></tr>
    <tr><td align=\"right\" >Variable9: </td><td colspan=\"5\">< input
    type=\"text\" name=\"Variable 9[]$Number2\" value=\"\" width=\"250\"/
    ></td></td><td colspan=\"21\">
    $msg[$Number]</td></tr>
    <tr><td colspan=\"60\"> &nbsp;</td></tr>
    <tr><td colspan=\"60\" bgcolor=\"#CCCC CC\">1. Question 10?</td></
    tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 10]$Number2\" type=
    \"radio\" value=\"Excelle nt\" />Excellent</td>
    <td align=\"center\ " ><input name=\"Variable 10[]$Number2\" type=
    \"radio\" value=\"Good\" />Good</td>
    <td align=\"center\ " ><input name=\"Variable 10[]$Number2\" type=
    \"radio\" value=\"Average \" />Average</td>
    <td align=\"center\ " ><input name=\"Variable 10[]$Number2\" type=
    \"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\"> $msg[$Number]</
    td>
    </tr>
    <tr><td colspan=\"60\" bgcolor=\"#CCCC CC\">2. Question 11?</td></
    tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 11[]$Number2\" type=
    \"radio\" value=\"Excelle nt\" />Excellent</td>
    <td align=\"center\ "><input name=\"Variable 11[]$Number2\" type=
    \"radio\" value=\"Good\" />Good</td>
    <td align=\"center\ "><input name=\"Variable 11[]$Number2\" type=
    \"radio\" value=\"Average \" />Average</td>
    <td align=\"center\ "><input name=\"Variable 11[]$Number2\" type=
    \"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\"$ msg[$Number]
    </td>
    </tr>
    <tr><td colspan=\"60\" bgcolor=\"#CCCC CC\">3. Question 12?</td></
    tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 12[]$Number2\" type=
    \"radio\" value=\"Excelle nt\" />Excellent</td>
    <td align=\"center\ "><input name=\"Encourag ed[]$Number2\" type=
    \"radio\" value=\"Good\" />Good</td>
    <td align=\"center\ "><input name=\"Variable 12[]$Number2\" type=
    \"radio\" value=\"Average \" />Average</td>
    <td align=\"center\ "><input name=\"Variable 12[]$Number2\" type=
    \"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\"> $msg[$Number]</
    td></tr>
    <tr><td colspan=\"60\" bgcolor=\"#CCCC CC\">4. Question 13
    </td></tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 13[]$Number2\" type=
    \"radio\" value=\"Excelle nt\" />Excellent</td>
    <td align=\"center\ "><input name=\"Variable 13[]$Number2\" type=
    \"radio\" value=\"Good\" />Good</td>
    <td align=\"center\ "><input name=\"Variable 13[]$Number2\" type=
    \"radio\" value=\"Average \" />Average</td>
    <td align=\"center\ "><input name=\"Variable 13[]$Number2\" type=
    \"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\"> $msg[$Number]</
    td>
    </tr>
    <tr><td colspan=\"60\" bgcolor=\"#CCCC CC\"5.Question 14? </
    td></tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 14[]$Number2\" type=
    \"radio\" value=\"Excelle nt\" />Excellent</td>
    <td align=\"center\ "><input name=\"Variable 14[]$Number2\" type=
    \"radio\" value=\"Good\" />Good</td>
    <td align=\"center\ "><input name=\"Variable 14[]$Number2\" type=
    \"radio\" value=\"Average \" />Average</td>
    <td align=\"center\ "><input name=\"Variable 14[]$Number2\" type=
    \"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\"> $msg[$Number]</
    td></tr>
    <tr><td colspan=\"60\" bgcolor=\"#CCCC CC\">6.Questio n 15?. </td>
    </tr>
    <tr>
    <td align=\"center\ "><input name=\"Variable 15[]$Number2\" type=
    \"radio\" value=\"Excelle nt\" />Excellent</td>
    <td align=\"center\ "><input name=\"Variable 15[]$Number2\" type=
    \"radio\" value=\"Good\" />Good</td>
    <td align=\"center\ "><input name=\"Variable 15[]$Number2\" type=
    \"radio\" value=\"Average \"/>Average</td>
    <td align=\"center\ "><input name=\"Variable 15[]$Number2\" type=
    \"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\"> $msg[$Number]</
    td></tr>
    <tr><td colspan=\"60\"> <hr/></td></tr>
    </table><br/>";

    $Number2++;
    $SeminarNumber+ +;
    } //Closes While Loop

    echo "<table width=\"700\" border=\"0\" cellpadding=\"0 \" align=
    \"center\">
    <tr><td colspan=\"60\" bgcolor=\"#CCCC CC\">Question 16: </td>
    </tr>
    <tr><td colspan=\"60\" align=\"center\ "><div align=\"center
    \"><textarea name=\"Variable 16[]\" cols=\"83\" rows=\"5\"></textarea>
    </div></td></tr>
    <tr><td>&nbsp;< input type=\"hidden\" name=\"Check\" value=\"1\"</
    td></tr>
    <tr><td bgcolor=\"#CCCC CC\">ADDITIONA L COMMENTS: </td></tr>
    <tr><td><div align=\"center\ "><textarea name=\"Variable 17[]\" cols=
    \"83\" rows=\"10\"></textarea></div><br/></td></tr>
    </table>
    <div align=\"center\ "><br/>If you are interested in receiving
    information or materials, please email me at <a href=
    \"mailto:email@ email.com\">ema il@email.com</a>.</div>
    <div align=\"center\ "><br/><input name=\"Submit\" type=\"Submit\"
    value=\"Submit\ ">
    &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;<input name=\"Reset\" type=
    \"Reset\" value=\"Reset\" ></div>
    </form>";
    } //closes the IF ($Number2>0) loop for if the user entered a
    number for seminars

    } //closes the IF ($error>0) loop
    else{
    include('submit .php');
    }
    } //closes the check POST validation IF


    else{
    echo"You can not access this page directly. To complete the survey,
    go to
    <br/><a href =\"http://www.website.com/index.php\">Sur vey Form</a>";
    }
    ?>

    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.

  • Rami Elomaa

    #2
    Re: Problem with a script

    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($Variabl e1)){
    $msg1=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e2)){
    $msg2=" * You have not answered this question.";
    $error++;
    }
    if (empty($Variabl e3)){
    $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($Variabl e[$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.Elomaa@gma il.com
    "Olemme apinoiden planeetalla."

    Comment

    • Schraalhans Keukenmeester

      #3
      Re: Problem with a script

      Jerim79 wrote:
      Here it is:
      >
      <?php
      >
      if($_SERVER['REQUEST_METHOD ']=='POST'){
      >
      [snip]
      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.
      I don't mean to offend you or discourage you from working with PHP, but:
      The way you coded the posted script gives me the impression you haven't
      yet grasped and practiced with the basic building blocks of PHP or maybe
      even programming in general. (See Rami's comments)

      Reworking your huge script into something concise, correct and 'a common
      sense coding practise' would probably result in a script hardly
      comparable to yours, rendering it mostly useless as a learning
      possibility. Commenting/correcting on a line by line basis would require
      a post a mile longer than your is already.

      If all you really want is a fix for a specific detail, give us only that
      and leave out the rest.

      Personally I think you may be helped more by leaving this spaghetti for
      later, and start getting to grips with PHP's building blocks first. Get
      a good (e-)book or tutorial site and begin with short examples and
      experiments that help you understand the concepts and PHP's way of doing
      things. I know they say PHP has a short learning curve, and compared to
      some/many other languages it probably does, but trying to sail even the
      simplest boat before you know bow from stern is not advisable.

      If I am completely off the mark here, I'm sorry. I just can't find
      anything in this post that proves me wrong.

      Which books/sites are good/great/rubbish is mainly a subjective choice.
      O'Reilly has a few that match MY taste, some are fond of the YOU-NAME-IT
      for Dummies approach, others prefer a really dry & theoretical but very
      exhausting summary. The pick is yours!

      GL.

      Sh.



      Comment

      • Jerim79

        #4
        Re: Problem with a script

        On Apr 10, 5:15 pm, Schraalhans Keukenmeester <bitbuc...@inva lid.spam>
        wrote:
        Jerim79 wrote:
        Here it is:
        >
        <?php
        >
        if($_SERVER['REQUEST_METHOD ']=='POST'){
        >
        [snip]
        >
        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.
        >
        I don't mean to offend you or discourage you from working with PHP, but:
        The way you coded the posted script gives me the impression you haven't
        yet grasped and practiced with the basic building blocks of PHP or maybe
        even programming in general. (See Rami's comments)
        >
        Reworking your huge script into something concise, correct and 'a common
        sense coding practise' would probably result in a script hardly
        comparable to yours, rendering it mostly useless as a learning
        possibility. Commenting/correcting on a line by line basis would require
        a post a mile longer than your is already.
        >
        If all you really want is a fix for a specific detail, give us only that
        and leave out the rest.
        >
        Personally I think you may be helped more by leaving this spaghetti for
        later, and start getting to grips with PHP's building blocks first. Get
        a good (e-)book or tutorial site and begin with short examples and
        experiments that help you understand the concepts and PHP's way of doing
        things. I know they say PHP has a short learning curve, and compared to
        some/many other languages it probably does, but trying to sail even the
        simplest boat before you know bow from stern is not advisable.
        >
        If I am completely off the mark here, I'm sorry. I just can't find
        anything in this post that proves me wrong.
        >
        Which books/sites are good/great/rubbish is mainly a subjective choice.
        O'Reilly has a few that match MY taste, some are fond of the YOU-NAME-IT
        for Dummies approach, others prefer a really dry & theoretical but very
        exhausting summary. The pick is yours!
        >
        GL.
        >
        Sh.
        This may come as a total shock to you, and if it does I apologize, but
        I don't really care what either of you think concerning my skills. I
        am proud of what I have, and it works. It may not be the way you
        personally would have done it, but then again, I am not you. To say
        that I have no understanding of loops is completely asinine. I use
        loops throughout the script. I don't use loops in every particular
        instance, because:
        1) The script is fresh and I want to maintain some sense of
        maintainability for the moment. Condensing things into loops is great
        once everything is working and you are sure that the loop will work/
        stay. When you are working on something, it is usually best to leave
        it in a "spread out" nature so that you can easily identify a problem
        as well as keep the design straight. Loops, especially in the early
        stages of a script, often become shrouds that cover up where the
        problem is occurring.
        2) This is not the final version of the script. Tightening up of
        a script occurs after you have it working. If you can build a script
        from scratch and code it perfectly the first time, every time, then
        good for you. Every one else in the universe though usually has to go
        through several iterations of a script before they are done. (True,
        given enough time, we should all theoretically spend much more time in
        design than production. But who has that kind of time?)
        3) I don't pretend that I will stay in the same position forever.
        Nor do I want some form that only mid level programmers will
        understand. When I create something, I want to make sure that someone
        else will be able to understand it. Sure, we could all code something
        as condensed/complicated as we can, but what of the poor programmer
        who comes behind us, who may not be as skilled? I try to straddle the
        line between efficient code and maintainable code by a reasonably
        knowledgeable programmer for my position. If I am working at small
        business with a history of hiring low knowledge employees, I dumb it
        down. If I am working at a Fortune 500 company with a history of
        hiring only the brightest, then I wouldn't see a problem going as far
        you want. I am not saying this applies in this case, but I wanted to
        throw that in while I am on the subject of programming.

        I have no fundamental knowledge of programming, eh? Really? I can
        program in Java, C++, and VB.net. Although I will never present myself
        as an expert programmer, maybe not even an experienced one, I most
        certainly have a solid grasp of programming. Just because a person
        doesn't do something the way you would do it at any particular stage
        in the process, doesn't mean they don't have a clue. That is a very
        arrogant attitude. I guess like Rami, you are basing that off of me
        not using a loop in every particular place that you feel I should. I
        wonder if you two would go to the start of the assembly line at the
        auto factory, and complain that the car doesn't even have windows
        yet.

        As for the loop that was given, it may surprise you that I don't label
        my variables as $VariableX. Variables should have unique names that
        signify what they are. Seeing as how I have unique names for my
        variables, a loop there becomes impractical. Unless of course I
        utilize pointers, which is open to a matter of discussion of whether
        it is worth it or not.

        The number one goal should always be to make it work. Trying to
        impress everyone with your made programming skills should always take
        a back seat to that. But thanks for the criticism that completely
        didn't address my question in any form. That was greatly appreciated.
        BTW, I was able to solve my own problem. I might even go back and take
        out all the loops, remove local variables, take out the method check,
        and the data verification. You know, since I don't know what I am
        doing and all. :)

        Comment

        • Jerim79

          #5
          Re: Problem with a script

          This may come as a total shock to you, and if it does I apologize, but
          I don't really care what either of you think concerning my skills. I
          am proud of what I have, and it works. It may not be the way you
          personally would have done it, but then again, I am not you. To say
          that I have no understanding of loops is completely asinine. I use
          loops throughout the script. I don't use loops in every particular
          instance, because:
          1) The script is fresh and I want to maintain some sense of
          maintainability for the moment. Condensing things into loops is great
          once everything is working and you are sure that the loop will work/
          stay. When you are working on something, it is usually best to leave
          it in a "spread out" nature so that you can easily identify a problem
          as well as keep the design straight. Loops, especially in the early
          stages of a script, often become shrouds that cover up where the
          problem is occurring.
          2) This is not the final version of the script. Tightening up of
          a script occurs after you have it working. If you can build a script
          from scratch and code it perfectly the first time, every time, then
          good for you. Every one else in the universe though usually has to go
          through several iterations of a script before they are done. (True,
          given enough time, we should all theoretically spend much more time in
          design than production. But who has that kind of time?)
          3) I don't pretend that I will stay in the same position forever.
          Nor do I want some form that only mid level programmers will
          understand. When I create something, I want to make sure that someone
          else will be able to understand it. Sure, we could all code something
          as condensed/complicated as we can, but what of the poor programmer
          who comes behind us, who may not be as skilled? I try to straddle the
          line between efficient code and maintainable code by a reasonably
          knowledgeable programmer for my position. If I am working at small
          business with a history of hiring low knowledge employees, I dumb it
          down. If I am working at a Fortune 500 company with a history of
          hiring only the brightest, then I wouldn't see a problem going as far
          you want. I am not saying this applies in this case, but I wanted to
          throw that in while I am on the subject of programming.

          I have no fundamental knowledge of programming, eh? Really? I can
          program in Java, C++, and VB.net. Although I will never present myself
          as an expert programmer, maybe not even an experienced one, I most
          certainly have a solid grasp of programming. Just because a person
          doesn't do something the way you would do it at any particular stage
          in the process, doesn't mean they don't have a clue. That is a very
          arrogant attitude. I guess like Rami, you are basing that off of me
          not using a loop in every particular place that you feel I should. I
          wonder if you two would go to the start of the assembly line at the
          auto factory, and complain that the car doesn't even have windows
          yet.

          As for the loop that was given, it may surprise you that I don't label
          my variables as $VariableX. Variables should have unique names that
          signify what they are. Seeing as how I have unique names for my
          variables, a loop there becomes impractical. Unless of course I
          utilize pointers, which is open to a matter of discussion of whether
          it is worth it or not.

          The number one goal should always be to make it work. Trying to
          impress everyone with your mad programming skills should always take
          a back seat to that. But thanks for the criticism that completely
          didn't address my question in any form. That was greatly appreciated.
          BTW, I was able to solve my own problem. I might even go back and take
          out all the loops, remove local variables, take out the method check,
          and the data verification. You know, since I don't know what I am
          doing and all. :)

          Comment

          • Rami Elomaa

            #6
            Re: Problem with a script

            Jerim79 kirjoitti:
            As for the loop that was given, it may surprise you that I don't label
            my variables as $VariableX. Variables should have unique names that
            signify what they are. Seeing as how I have unique names for my
            variables, a loop there becomes impractical. Unless of course I
            utilize pointers, which is open to a matter of discussion of whether
            it is worth it or not.
            Okay, so variables have unique labels, that doesn't mean they still
            couldn't be handled in a loop. I'll just tell you what I personally
            would do, and I'm not trying to say this is how you should do it.

            Php's arrays can be both indexed and associative, I'd use the lable
            strings as keys instead of numbers.

            Okay, so the variables aren't called $variable1, $variable2, but let's
            say Peter, Paul and Mary, etc... So just make a array of them:
            $my_labels = array('Peter', 'Paul', 'Mary',);

            Collect the values from form:
            foreach($my_lab els as $key)
            $my_values[$key] = $_POST[$key];

            Then check for errors:
            foreach($my_val ues as $key =$val)
            if (empty($val)){
            $msg[$key] = " * You have not answered this question.";
            $error++;
            }

            You still have them as uniquely named array indexes... (indices? whatever.)

            I believe that for the new guy this code would be readable, and
            identifying problems should really not be any more difficult with this,
            plus I think that it actually might save some time to write the actual
            code from the beginnig, even though it's not at it's final stage,
            instead of first writing everything spread out, and then rewriting the
            same code again cleaned. If anything, writing the code twice will only
            introduce new bugs which still would need to be detected.

            However, my original intent was not to concentrate on the bad code, err,
            your personal style of writing test code, but to draw your attention to
            the fact that there was so much of it. When you write to a forum such as
            this, requesting for help, do concider trimming the code to a very very
            short piece where the problem is shown. If you post several hundreds of
            lines of code, who's gonna start reading it all? Most just take a
            glimpse at it and think "spaghetti! " and ignore it. Had you isolated the
            problem to less than 20 lines, people might've actually paid attention
            to it and been able to help you with it. You see, people in c.l.php have
            the patience of an adhd child high on sugar. If the problem isn't solved
            within 10 seconds, it's ignored. If you expect a person to spend an hour
            reading your entire code and parsing it in their head, you wont get any
            help and have to solve the problem by yourself.

            I'm sure you have your own style of coding and after reading your
            explanation you've convinced me that you may not actually be entirely
            rookie in coding. The difficlty seems to be that you've not yet grasped
            the fine skill of posting a question to usenet. I wouldn't want to think
            that this was all waste of both of our time, so I'll try to learn the
            lesson here and not judge people and their code so harshly, if you'll
            consider sending shorter piece of sample code the next time you post,
            agreed? :)

            A final word on refusing to use loops is an educating story on Worse
            Than Failure (formerly known as The Daily WTF) that you might want to
            read: http://worsethanfailure.com/Articles...ur_Digits.aspx

            --
            Rami.Elomaa@gma il.com

            "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
            usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

            Comment

            • Tim Streater

              #7
              Re: Problem with a script

              In article <evll5o$ont$1@n yytiset.pp.htv. fi>,
              Rami Elomaa <rami.elomaa@gm ail.comwrote:

              [snip]
              You still have them as uniquely named array indexes... (indices? whatever.)
              >
              I believe that for the new guy this code would be readable, and
              identifying problems should really not be any more difficult with this,
              plus I think that it actually might save some time to write the actual
              code from the beginnig, even though it's not at it's final stage,
              instead of first writing everything spread out, and then rewriting the
              same code again cleaned. If anything, writing the code twice will only
              introduce new bugs which still would need to be detected.
              I agree it's very important to code clearly for those who will follow
              and probably maintain the code. The idea of making a working but messy
              version I find bizarre - probably the OP is much cleverer than me. I
              could never work this way; I prefer to take the time to construct the
              final version.
              However, my original intent was not to concentrate on the bad code, err,
              your personal style of writing test code, but to draw your attention to
              the fact that there was so much of it. When you write to a forum such as
              this, requesting for help, do concider trimming the code to a very very
              short piece where the problem is shown. If you post several hundreds of
              lines of code, who's gonna start reading it all?
              Not me that's for damn sure.
              Most just take a glimpse at it and think "spaghetti! " and ignore it.
              Just what I did.
              Had you isolated the
              problem to less than 20 lines, people might've actually paid attention
              to it and been able to help you with it. You see, people in c.l.php have
              the patience of an adhd child high on sugar. If the problem isn't solved
              within 10 seconds, it's ignored. If you expect a person to spend an hour
              reading your entire code and parsing it in their head, you wont get any
              help and have to solve the problem by yourself.
              Yep, that's it. You have to capture people's interest with your post.
              And there was no evidence that the OP had spent any time doing his own
              debugging and reducing the (as far as I could tell unspecified) problem
              to a short piece of code.
              I'm sure you have your own style of coding and after reading your
              explanation you've convinced me that you may not actually be entirely
              rookie in coding. The difficlty seems to be that you've not yet grasped
              the fine skill of posting a question to usenet. I wouldn't want to think
              that this was all waste of both of our time, so I'll try to learn the
              lesson here and not judge people and their code so harshly, if you'll
              consider sending shorter piece of sample code the next time you post,
              agreed? :)
              >
              A final word on refusing to use loops is an educating story on Worse
              Than Failure (formerly known as The Daily WTF) that you might want to
              read: http://worsethanfailure.com/Articles...ur_Digits.aspx
              Ouch.

              -- tim

              Comment

              • Jerim79

                #8
                Re: Problem with a script

                On Apr 10, 11:52 am, Rami Elomaa <rami.elo...@gm ail.comwrote:
                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($Variabl e1)){
                $msg1=" * You have not answered this question.";
                $error++;}
                >
                if (empty($Variabl e2)){
                $msg2=" * You have not answered this question.";
                $error++;}
                >
                if (empty($Variabl e3)){
                $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($Variabl e[$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...@gma il.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.

                Comment

                • Jerim79

                  #9
                  Re: Problem with a script

                  On Apr 12, 11:01 am, Rami Elomaa <rami.elo...@gm ail.comwrote:
                  Jerim79 kirjoitti:
                  >
                  As for the loop that was given, it may surprise you that I don't label
                  my variables as $VariableX. Variables should have unique names that
                  signify what they are. Seeing as how I have unique names for my
                  variables, a loop there becomes impractical. Unless of course I
                  utilize pointers, which is open to a matter of discussion of whether
                  it is worth it or not.
                  >
                  Okay, so variables have unique labels, that doesn't mean they still
                  couldn't be handled in a loop. I'll just tell you what I personally
                  would do, and I'm not trying to say this is how you should do it.
                  >
                  Php's arrays can be both indexed and associative, I'd use the lable
                  strings as keys instead of numbers.
                  >
                  Okay, so the variables aren't called $variable1, $variable2, but let's
                  say Peter, Paul and Mary, etc... So just make a array of them:
                  $my_labels = array('Peter', 'Paul', 'Mary',);
                  >
                  Collect the values from form:
                  foreach($my_lab els as $key)
                  $my_values[$key] = $_POST[$key];
                  >
                  Then check for errors:
                  foreach($my_val ues as $key =$val)
                  if (empty($val)){
                  $msg[$key] = " * You have not answered this question.";
                  $error++;
                  }
                  >
                  You still have them as uniquely named array indexes... (indices? whatever..)
                  >
                  I believe that for the new guy this code would be readable, and
                  identifying problems should really not be any more difficult with this,
                  plus I think that it actually might save some time to write the actual
                  code from the beginnig, even though it's not at it's final stage,
                  instead of first writing everything spread out, and then rewriting the
                  same code again cleaned. If anything, writing the code twice will only
                  introduce new bugs which still would need to be detected.
                  >
                  However, my original intent was not to concentrate on the bad code, err,
                  your personal style of writing test code, but to draw your attention to
                  the fact that there was so much of it. When you write to a forum such as
                  this, requesting for help, do concider trimming the code to a very very
                  short piece where the problem is shown. If you post several hundreds of
                  lines of code, who's gonna start reading it all? Most just take a
                  glimpse at it and think "spaghetti! " and ignore it. Had you isolated the
                  problem to less than 20 lines, people might've actually paid attention
                  to it and been able to help you with it. You see, people in c.l.php have
                  the patience of an adhd child high on sugar. If the problem isn't solved
                  within 10 seconds, it's ignored. If you expect a person to spend an hour
                  reading your entire code and parsing it in their head, you wont get any
                  help and have to solve the problem by yourself.
                  >
                  I'm sure you have your own style of coding and after reading your
                  explanation you've convinced me that you may not actually be entirely
                  rookie in coding. The difficlty seems to be that you've not yet grasped
                  the fine skill of posting a question to usenet. I wouldn't want to think
                  that this was all waste of both of our time, so I'll try to learn the
                  lesson here and not judge people and their code so harshly, if you'll
                  consider sending shorter piece of sample code the next time you post,
                  agreed? :)
                  >
                  A final word on refusing to use loops is an educating story on Worse
                  Than Failure (formerly known as The Daily WTF) that you might want to
                  read:http://worsethanfailure.com/Articles...ur_Digits.aspx
                  >
                  --
                  Rami.Elo...@gma il.com
                  >
                  "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
                  usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
                  Perhaps I was too hasty in my original reply and if so, I apologize. I
                  certainly don't want to take all my frustration out on one person.
                  Having been around programmers for a while, I have run into the "My
                  way is the only way" attitude. Perhaps I am too quick to pounce on
                  anyone who I think exhibits that behavior, even if they don't. My
                  apologies. I always love to learn new things.

                  Comment

                  • Schraalhans Keukenmeester

                    #10
                    Re: Problem with a script

                    Jerim79 wrote:
                    On Apr 12, 11:01 am, Rami Elomaa <rami.elo...@gm ail.comwrote:
                    >Jerim79 kirjoitti:
                    >>
                    >>As for the loop that was given, it may surprise you that I don't label
                    >>my variables as $VariableX. Variables should have unique names that
                    >>signify what they are. Seeing as how I have unique names for my
                    >>variables, a loop there becomes impractical. Unless of course I
                    >>utilize pointers, which is open to a matter of discussion of whether
                    >>it is worth it or not.
                    >Okay, so variables have unique labels, that doesn't mean they still
                    >couldn't be handled in a loop. I'll just tell you what I personally
                    >would do, and I'm not trying to say this is how you should do it.
                    >>
                    >Php's arrays can be both indexed and associative, I'd use the lable
                    >strings as keys instead of numbers.
                    >>
                    >Okay, so the variables aren't called $variable1, $variable2, but let's
                    >say Peter, Paul and Mary, etc... So just make a array of them:
                    >$my_labels = array('Peter', 'Paul', 'Mary',);
                    >>
                    >Collect the values from form:
                    >foreach($my_la bels as $key)
                    > $my_values[$key] = $_POST[$key];
                    >>
                    >Then check for errors:
                    >foreach($my_va lues as $key =$val)
                    > if (empty($val)){
                    > $msg[$key] = " * You have not answered this question.";
                    > $error++;
                    > }
                    >>
                    >You still have them as uniquely named array indexes... (indices? whatever.)
                    >>
                    >I believe that for the new guy this code would be readable, and
                    >identifying problems should really not be any more difficult with this,
                    >plus I think that it actually might save some time to write the actual
                    >code from the beginnig, even though it's not at it's final stage,
                    >instead of first writing everything spread out, and then rewriting the
                    >same code again cleaned. If anything, writing the code twice will only
                    >introduce new bugs which still would need to be detected.
                    >>
                    >However, my original intent was not to concentrate on the bad code, err,
                    >your personal style of writing test code, but to draw your attention to
                    >the fact that there was so much of it. When you write to a forum such as
                    >this, requesting for help, do concider trimming the code to a very very
                    >short piece where the problem is shown. If you post several hundreds of
                    >lines of code, who's gonna start reading it all? Most just take a
                    >glimpse at it and think "spaghetti! " and ignore it. Had you isolated the
                    >problem to less than 20 lines, people might've actually paid attention
                    >to it and been able to help you with it. You see, people in c.l.php have
                    >the patience of an adhd child high on sugar. If the problem isn't solved
                    >within 10 seconds, it's ignored. If you expect a person to spend an hour
                    >reading your entire code and parsing it in their head, you wont get any
                    >help and have to solve the problem by yourself.
                    >>
                    >I'm sure you have your own style of coding and after reading your
                    >explanation you've convinced me that you may not actually be entirely
                    >rookie in coding. The difficlty seems to be that you've not yet grasped
                    >the fine skill of posting a question to usenet. I wouldn't want to think
                    >that this was all waste of both of our time, so I'll try to learn the
                    >lesson here and not judge people and their code so harshly, if you'll
                    >consider sending shorter piece of sample code the next time you post,
                    >agreed? :)
                    >>
                    >A final word on refusing to use loops is an educating story on Worse
                    >Than Failure (formerly known as The Daily WTF) that you might want to
                    >read:http://worsethanfailure.com/Articles...ur_Digits.aspx
                    >>
                    >--
                    >Rami.Elo...@gm ail.com
                    >>
                    >"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
                    >usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
                    >
                    Perhaps I was too hasty in my original reply and if so, I apologize. I
                    certainly don't want to take all my frustration out on one person.
                    Having been around programmers for a while, I have run into the "My
                    way is the only way" attitude. Perhaps I am too quick to pounce on
                    anyone who I think exhibits that behavior, even if they don't. My
                    apologies. I always love to learn new things.
                    >
                    IIRC I inclued a line saying: If I am wrong, then [...] The word sorry
                    being part of it.
                    I also said: from what you POSTED I got the idea [...]
                    I still think there's nothing insulting about my reply btw, and I can
                    assure you it was written with best intent.
                    I can live with your sarcasm, I hope you understand nonetheless
                    _APPARANTLY_ your post triggered a few responses you had not expected.

                    Most people here seriously try to help out if they can. And sometimes
                    they fail at giving the response someone was hoping for. Fact of usenet
                    life. Getting a storm in return also seems to be one. C'est la vie!

                    Sh.





                    Comment

                    Working...