SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: If Statement

Hybrid View

  1. #1
    SitePoint Zealot Fizlar's Avatar
    Join Date
    Aug 2003
    Location
    Sheffield
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile If Statement

    HI i have done a questionnaire and when they submit i want the page to say thank you ... i can get it to do that but cant stop it from showing the rest of the form

    i am trying to get the form to dissappear after they have submitted their responces???

    PHP Code:
    <?php
    // check to see if the user has submitted the form
    if( isset( $_POST['course'] ) ) {
       echo
    "THANK YOU";
     }

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Feedback Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body><form name="BasicForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    My name is Fizlar and I am currently studying for my Masters degree in Information 
    Systems at the University of Sheffield, England. This questionnaire is part of 
    my on-going research to try to gain a comprehensive understanding of the problems 
    that users like yourself experience when querying a database.<br>
    <p>&nbsp;</p>
    <form method="post">
    <p>Can You Please type your age </p>
      <input name="AGE" type="text" value="AGE" size="10">
    <p>What is your first language if not English</p>
     <textarea name="LANG" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>

    <p>&nbsp;</p>

      <p>Q1, WHAT, IF ANYTHING, WOULD YOU SAY HINDERS YOUR ABILITY TO USE A COMPUTER 
        EFFECTIVLY?</p>
      <p> 
        <textarea name="QUES1" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
      
      <p>Q2, IN WHAT WAY DOES YOUR NATIVE LANGUAGE AFFECT YOUR ABILITY TO SEARCH FOR 
        A PARTICULAR PIECE OF INFORMATION?
      <p> 
        <textarea name="QUES2" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
      
      <p>Q3, DO YOU THINK THIS TYPE OF SEARCHING IS HELPFUL? </p>
      <p> 
        <input type="radio" name="rating1" value="1">
        1 Very Helpful<br />
        <input type="radio" name="rating1" value="2">
        2 Helpful<br />
        <input type="radio" name="rating1" value="3">
        3 Uudecided<br />
        <input type="radio" name="rating1" value="4">
        4 Unhelpful<br />
        <input type="radio" name="rating1" value="5">
        5 Very Unhelpful<br />
      <p>Q4, WHEN SUBMITTING YOUR FIRST QUERY, WERE THE RESULTS RETURNED SATISFACTORY 
        TO <br>
        YOUR NEEDS?</p>
      <p> 
        <input type="radio" name="rating2" value="1">
        1 Very Satisfactory<br />
        <input type="radio" name="rating2" value="2">
        2 Satisfactory<br />
        <input type="radio" name="rating2" value="3">
        3 Undecided<br />
        <input type="radio" name="rating2" value="4">
        4 Unsatisfactory<br />
        <input type="radio" name="rating2" value="5">
        5 Very Unsatisfactory
      <p>Q5, IF NOT SATISFACTORY WHY NOT? 
      <p>
        <textarea name="QUES5" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
      <br />
      
      <p>Q6, HOW USEFUL DID YOU FIND THE RESULTS FROM YOUR FIRST QUERY? </p>
      <p> 
        <input type="radio" name="rating3" value="1">
        1 Very Useful<br />
        <input type="radio" name="rating3" value="2">
        2 Useful<br />
        <input type="radio" name="rating3" value="3">
        3 Undecided<br />
        <input type="radio" name="rating3" value="4">
        4 Unhelpful<br />
        <input type="radio" name="rating3" value="5">
        5 Very Unhelpful<br />
      </p>
      <p>Q7, DID THE RESULTS OF THE FIRST QUERY, SUPPORT YOU IN FINDING THE INFORMATION 
        YOU REQUIRED? </p>
      <p> 
        <input type="radio" name="rating4" value="1">
        1 Yes<br />
        <input type="radio" name="rating4" value="2">
        2 No <br />
        <input type="radio" name="rating4" value="3">
        3 Undecided <br />
      </p>
      <p>Q8, IF YOU WERE UNABLE TO RETRIEVE THE INFORMATION YOU REQUIRED FIRST TIME 
        WERE YOU <br>
        ABLE TO RETRIEVE IT ON SUBSEQUENT SEARCHES? </p>
      <p> 
        <input type="radio" name="rating5" value="3">
        1 Yes<br />
        <input type="radio" name="rating5" value="2">
        2 No<br />
        <input type="radio" name="rating5" value="1">
        3 Undecided<br />
      <p>Q9, WERE THERE ANY PARTS OF THE QUERYING PROCESS THAT WERE PARTICULARLY DIFFICULT 
        TO USE? 
      <p> 
        <textarea name="QUES9" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
      <p>&nbsp; 
      <p>Q10, DO YOU FIND THIS TYPE OF DESIGN USEFUL TO YOU IN FINDING INFORMATON?</p>
      <p> 
        <input type="radio" name="rating6" value="1">
        1 Very Useful<br />
        <input type="radio" name="rating6" value="2">
        2 Useful<br />
        <input type="radio" name="rating6" value="3">
        3 Undecided<br />
        <input type="radio" name="rating6" value="4">
        4 Unhelpful<br />
        <input type="radio" name="rating6" value="5">
        5 Very Unhelpful</p>
      <p>Q11, OVERALL, HOW DID THIS WEBSITE ASSIST YOU INTO FINDING INFORMATION YOU 
        REQUIRED? </p>
      <p> 
        <input type="radio" name="rating7" value="1">
        1 Very Helpful<br />
        <input type="radio" name="rating7" value="2">
        2 Useful<br />
        <input type="radio" name="rating7" value="3">
        3 Undecided<br />
        <input type="radio" name="rating7" value="4">
        4 Unhelpful<br />
        <input type="radio" name="rating7" value="5">
        5 Very Unhelpful</p>
      <p>Q12, WAS THE LAYOUT OF THE WEBSITE CLEAR AND EASY TO NAVIGATE?</p>
      <p> 
        <input type="radio" name="rating8" value="1">
        1 Yes<br />
        <input type="radio" name="rating8" value="2">
        2 No<br />
        <input type="radio" name="rating8" value="3">
        3 Undecided<br />
      </p>
      <p>Q13, IF NOWHY NOT? </p>
      <p> 
        <textarea name="QUES13" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
        <br />
      <p> Q14, CAN YOU SUGGEST ANY FUTURE IMPROVEMENTS THAT COULD MAKE THE LOOK AND 
        FEEL OF THE SITE EASIER TO USE? 
      <p> 
        <textarea name="QUES14" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
      
      <p>Q15, COMPARED TO ANY PREVIOUS EXPERIENCE IN QUERYING FOR INFORMATION - HOW 
        DID THIS<br>
        SEARCH ENGINE FARE IN COMPARISON?</p>
      <p> 
        <input type="radio" name="rating9" value="1">
        1 Very Useful<br />
        <input type="radio" name="rating9" value="2">
        2 Useful<br />
        <input type="radio" name="rating9" value="3">
        3 Undecided<br />
        <input type="radio" name="rating9" value="4">
        4 Unhelpful<br />
        <input type="radio" name="rating9" value="5">
        5 Very Unhelpful</p>
        
      <p>Q16, CAN YOU SUGGEST ANY FURTHER IMPROVEMENTS THAT WOULD ASSIST YOU IN THE 
        QUERYING PROCESS?</p>
      <p> 
        <textarea name="QUES16" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
      
      <p>Q17, HOW WOULD YOU RATE THIS SEARCH ENGINE ON A SCALE OF 1 – 5 WHERE 
        ONE IS VERY POOR AND FIVE IS EXCELLENT?</p>
      <p> 
        <input type="radio" name="rating10" value="1">
        1 Very Poor<br />
        <input type="radio" name="rating10" value="2">
        2 Poor<br />
        <input type="radio" name="rating10" value="3">
        3 Undecided<br />
        <input type="radio" name="rating10" value="4">
        4 Good<br />
        <input type="radio" name="rating10" value="5">
        5 Excellentl</p>
      <p> 
        <input type="submit" name="course" value="Submit">
      </p>
      </form>
    <?
      $R1 
    $_REQUEST['rating1']; 
      
    $R2 $_REQUEST['rating2']; 
      
    $R3 $_REQUEST['rating3']; 
      
    $R4 $_REQUEST['rating4']; 
      
    $R5 $_REQUEST['rating5']; 
      
    $R6 $_REQUEST['rating6']; 
      
    $R7 $_REQUEST['rating7']; 
      
    $R8 $_REQUEST['rating8']; 
      
    $R9 $_REQUEST['rating9']; 
      
    $R10 $_REQUEST['rating10']; 
      
    $Tx1 $_REQUEST['QUES1'];
      
    $Tx2 $_REQUEST['QUES2'];
      
    $Tx3 $_REQUEST['QUES5'];
      
    $Tx4 $_REQUEST['QUES9'];
      
    $Tx5 $_REQUEST['QUES13'];
      
    $Tx6 $_REQUEST['QUES14'];
      
    $Tx7 $_REQUEST['QUES16'];  
      
    $age $_REQUEST['AGE'];
      
    $lang $_REQUEST['LANG'];

    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17) VALUES (NULL,'$age','$lang','$Tx1','$Tx2','$R1','$R2','$Tx3','$R3','$R4','$R5','$Tx4','$R6','$R7','$R8','$Tx5','$Tx6','$R9','$Tx7','$R10')"


    $user "****";
    $pass "***** ";
    $db "***";
    $link mysql_connect"localhost"$user$pass );
    if (! 
    $link)
        die (
    "could not connect to MySQL");
    mysql_select_db ($db)
        or die (
    "could not connect to $db: ".mysql_error() );

    $result mysql_query ($sql);

    ?>

    /body>
    </html>

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    You need to add a else part. I've also moved the insert query, so it will only be executed if the $_POST['course'] is set.
    Try:
    PHP Code:
    <?php 
    // check to see if the user has submitted the form 
    if( isset( $_POST['course'] ) ) { 
        echo
    "THANK YOU"

        
    $R1 $_REQUEST['rating1']; 
        
    $R2 $_REQUEST['rating2']; 
        
    $R3 $_REQUEST['rating3']; 
        
    $R4 $_REQUEST['rating4']; 
        
    $R5 $_REQUEST['rating5']; 
        
    $R6 $_REQUEST['rating6']; 
        
    $R7 $_REQUEST['rating7']; 
        
    $R8 $_REQUEST['rating8']; 
        
    $R9 $_REQUEST['rating9']; 
        
    $R10 $_REQUEST['rating10']; 
        
    $Tx1 $_REQUEST['QUES1']; 
        
    $Tx2 $_REQUEST['QUES2']; 
        
    $Tx3 $_REQUEST['QUES5']; 
        
    $Tx4 $_REQUEST['QUES9']; 
        
    $Tx5 $_REQUEST['QUES13']; 
        
    $Tx6 $_REQUEST['QUES14']; 
        
    $Tx7 $_REQUEST['QUES16'];   
        
    $age $_REQUEST['AGE']; 
        
    $lang $_REQUEST['LANG']; 

        
    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17) VALUES (NULL,'$age','$lang','$Tx1','$Tx2','$R1','$R2','$Tx3','$R3','$R4','$R5','$Tx4','$R6','$R7','$R8','$Tx5','$Tx6','$R9','$Tx7','$R10'  )"


        
    $user "****"
        
    $pass "***** "
        
    $db "***"
        
    $link mysql_connect"localhost"$user$pass ); 
        if (! 
    $link
            die (
    "could not connect to MySQL" ); 
        
    mysql_select_db ($db
            or die (
    "could not connect to $db: ".mysql_error() ); 

        
    $result mysql_query ($sql); 
        }
    } else {

    ?> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
    <head> 
    <title>Feedback Form</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    </head> 

    <body><form name="BasicForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 

    My name is Fizlar and I am currently studying for my Masters degree in Information 
    Systems at the University of Sheffield, England. This questionnaire is part of 
    my on-going research to try to gain a comprehensive understanding of the problems 
    that users like yourself experience when querying a database.<br> 
    <p>&nbsp;</p> 
    <form method="post"> 
    <p>Can You Please type your age </p> 
      <input name="AGE" type="text" value="AGE" size="10"> 
    <p>What is your first language if not English</p> 
    <textarea name="LANG" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

    <p>&nbsp;</p> 

        <p>Q1, WHAT, IF ANYTHING, WOULD YOU SAY HINDERS YOUR ABILITY TO USE A COMPUTER EFFECTIVLY?</p> 
        <p> 
        <textarea name="QUES1" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

        <p>Q2, IN WHAT WAY DOES YOUR NATIVE LANGUAGE AFFECT YOUR ABILITY TO SEARCH FOR 
        A PARTICULAR PIECE OF INFORMATION? 
        <p> 
        <textarea name="QUES2" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

        <p>Q3, DO YOU THINK THIS TYPE OF SEARCHING IS HELPFUL? </p> 
        <p> 
        <input type="radio" name="rating1" value="1"> 
        1 Very Helpful<br /> 
        <input type="radio" name="rating1" value="2"> 
        2 Helpful<br /> 
        <input type="radio" name="rating1" value="3"> 
        3 Uudecided<br /> 
        <input type="radio" name="rating1" value="4"> 
        4 Unhelpful<br /> 
        <input type="radio" name="rating1" value="5"> 
        5 Very Unhelpful<br /> 
        <p>Q4, WHEN SUBMITTING YOUR FIRST QUERY, WERE THE RESULTS RETURNED SATISFACTORY 
        TO <br> 
        YOUR NEEDS?</p> 
        <p> 
        <input type="radio" name="rating2" value="1"> 
        1 Very Satisfactory<br /> 
        <input type="radio" name="rating2" value="2"> 
        2 Satisfactory<br /> 
        <input type="radio" name="rating2" value="3"> 
        3 Undecided<br /> 
        <input type="radio" name="rating2" value="4"> 
        4 Unsatisfactory<br /> 
        <input type="radio" name="rating2" value="5"> 
        5 Very Unsatisfactory 
        <p>Q5, IF NOT SATISFACTORY WHY NOT? 
        <p> 
        <textarea name="QUES5" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 
        <br /> 

        <p>Q6, HOW USEFUL DID YOU FIND THE RESULTS FROM YOUR FIRST QUERY? </p> 
        <p> 
        <input type="radio" name="rating3" value="1"> 
        1 Very Useful<br /> 
        <input type="radio" name="rating3" value="2"> 
        2 Useful<br /> 
        <input type="radio" name="rating3" value="3"> 
        3 Undecided<br /> 
        <input type="radio" name="rating3" value="4"> 
        4 Unhelpful<br /> 
        <input type="radio" name="rating3" value="5"> 
        5 Very Unhelpful<br /> 
        </p> 
        <p>Q7, DID THE RESULTS OF THE FIRST QUERY, SUPPORT YOU IN FINDING THE INFORMATION 
        YOU REQUIRED? </p> 
        <p> 
        <input type="radio" name="rating4" value="1"> 
        1 Yes<br /> 
        <input type="radio" name="rating4" value="2"> 
        2 No <br /> 
        <input type="radio" name="rating4" value="3"> 
        3 Undecided <br /> 
        </p> 
        <p>Q8, IF YOU WERE UNABLE TO RETRIEVE THE INFORMATION YOU REQUIRED FIRST TIME 
        WERE YOU <br> 
        ABLE TO RETRIEVE IT ON SUBSEQUENT SEARCHES? </p> 
        <p> 
        <input type="radio" name="rating5" value="3"> 
        1 Yes<br /> 
        <input type="radio" name="rating5" value="2"> 
        2 No<br /> 
        <input type="radio" name="rating5" value="1"> 
        3 Undecided<br /> 
        <p>Q9, WERE THERE ANY PARTS OF THE QUERYING PROCESS THAT WERE PARTICULARLY DIFFICULT 
        TO USE? 
        <p> 
        <textarea name="QUES9" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 
        <p>&nbsp; 
        <p>Q10, DO YOU FIND THIS TYPE OF DESIGN USEFUL TO YOU IN FINDING INFORMATON?</p> 
        <p> 
        <input type="radio" name="rating6" value="1"> 
        1 Very Useful<br /> 
        <input type="radio" name="rating6" value="2"> 
        2 Useful<br /> 
        <input type="radio" name="rating6" value="3"> 
        3 Undecided<br /> 
        <input type="radio" name="rating6" value="4"> 
        4 Unhelpful<br /> 
        <input type="radio" name="rating6" value="5"> 
        5 Very Unhelpful</p> 
        <p>Q11, OVERALL, HOW DID THIS WEBSITE ASSIST YOU INTO FINDING INFORMATION YOU 
        REQUIRED? </p> 
        <p> 
        <input type="radio" name="rating7" value="1"> 
        1 Very Helpful<br /> 
        <input type="radio" name="rating7" value="2"> 
        2 Useful<br /> 
        <input type="radio" name="rating7" value="3"> 
        3 Undecided<br /> 
        <input type="radio" name="rating7" value="4"> 
        4 Unhelpful<br /> 
        <input type="radio" name="rating7" value="5"> 
        5 Very Unhelpful</p> 
        <p>Q12, WAS THE LAYOUT OF THE WEBSITE CLEAR AND EASY TO NAVIGATE?</p> 
        <p> 
        <input type="radio" name="rating8" value="1"> 
        1 Yes<br /> 
        <input type="radio" name="rating8" value="2"> 
        2 No<br /> 
        <input type="radio" name="rating8" value="3"> 
        3 Undecided<br /> 
        </p> 
        <p>Q13, IF NOWHY NOT? </p> 
        <p> 
        <textarea name="QUES13" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 
        <br /> 
        <p> Q14, CAN YOU SUGGEST ANY FUTURE IMPROVEMENTS THAT COULD MAKE THE LOOK AND 
        FEEL OF THE SITE EASIER TO USE? 
        <p> 
        <textarea name="QUES14" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

        <p>Q15, COMPARED TO ANY PREVIOUS EXPERIENCE IN QUERYING FOR INFORMATION - HOW 
        DID THIS<br> 
        SEARCH ENGINE FARE IN COMPARISON?</p> 
        <p> 
        <input type="radio" name="rating9" value="1"> 
        1 Very Useful<br /> 
        <input type="radio" name="rating9" value="2"> 
        2 Useful<br /> 
        <input type="radio" name="rating9" value="3"> 
        3 Undecided<br /> 
        <input type="radio" name="rating9" value="4"> 
        4 Unhelpful<br /> 
        <input type="radio" name="rating9" value="5"> 
        5 Very Unhelpful</p> 

        <p>Q16, CAN YOU SUGGEST ANY FURTHER IMPROVEMENTS THAT WOULD ASSIST YOU IN THE 
        QUERYING PROCESS?</p> 
        <p> 
        <textarea name="QUES16" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

        <p>Q17, HOW WOULD YOU RATE THIS SEARCH ENGINE ON A SCALE OF 1  5 WHERE 
        ONE IS VERY POOR AND FIVE IS EXCELLENT?</p> 
        <p> 
        <input type="radio" name="rating10" value="1"> 
        1 Very Poor<br /> 
        <input type="radio" name="rating10" value="2"> 
        2 Poor<br /> 
        <input type="radio" name="rating10" value="3"> 
        3 Undecided<br /> 
        <input type="radio" name="rating10" value="4"> 
        4 Good<br /> 
        <input type="radio" name="rating10" value="5"> 
        5 Excellentl</p> 
        <p> 
        <input type="submit" name="course" value="Submit"> 
        </p> 
        </form> 
    <? 
    }
    ?> 
    </body> 
    </html>
    HTH

    -Helge

  3. #3
    SitePoint Zealot Fizlar's Avatar
    Join Date
    Aug 2003
    Location
    Sheffield
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers that works perfectly....

    that now leads to my next question how can i make sure that

    the age lang fields are filled in and so are the rest of the question are filled in??

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe something like this. (I've cut away the form to make the post shorter)
    PHP Code:
    <?php 
    // check to see if the user has submitted the form 
    if(isset($_POST['course'])) { 
        
    $valid true;
        
    $errorFields = array();

        foreach(
    $_POST AS $key=>$value) {
            if(empty(
    $value)) {
                
    $valid false;
                
    $errorFields[] = $key;
        }

        if(
    $valid) {
            echo
    "THANK YOU"
            
    $R1 $_REQUEST['rating1']; 
            
    $R2 $_REQUEST['rating2']; 
            
    $R3 $_REQUEST['rating3']; 
            
    $R4 $_REQUEST['rating4']; 
            
    $R5 $_REQUEST['rating5']; 
            
    $R6 $_REQUEST['rating6']; 
            
    $R7 $_REQUEST['rating7']; 
            
    $R8 $_REQUEST['rating8']; 
            
    $R9 $_REQUEST['rating9']; 
            
    $R10 $_REQUEST['rating10']; 
            
    $Tx1 $_REQUEST['QUES1']; 
            
    $Tx2 $_REQUEST['QUES2']; 
            
    $Tx3 $_REQUEST['QUES5']; 
            
    $Tx4 $_REQUEST['QUES9']; 
            
    $Tx5 $_REQUEST['QUES13']; 
            
    $Tx6 $_REQUEST['QUES14']; 
            
    $Tx7 $_REQUEST['QUES16'];   
            
    $age $_REQUEST['AGE']; 
            
    $lang $_REQUEST['LANG']; 

            
    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17) VALUES (NULL,'$age','$lang','$Tx1','$Tx2','$R1','$R2','$Tx3','$R3','$R4','$R5','$Tx4','$R6','$R7','$R8','$Tx5','$Tx6','$R9','$Tx7','$R10'  )"


            
    $user "****"
            
    $pass "***** "
            
    $db "***"
            
    $link mysql_connect"localhost"$user$pass ); 
            if (! 
    $link
                die (
    "could not connect to MySQL" ); 
                
    mysql_select_db ($db) or die ("could not connect to $db: ".mysql_error() ); 
                
    $result mysql_query ($sql); 
            }
        echo 
    '</body></html> ';
        exit;
        }
    }

    if(!
    $valid) {
        echo 
    "The following fields must be filled out:<br />";
        foreach(
    $errorFields AS $value) {
            echo 
    " - $value<br />\n";
        }
    }
    ?>


    <!-- HTML form -->


    </body>
    </html>
    Not tested

    HTH

    -Helge

  5. #5
    ko pročita magarac :) boccio's Avatar
    Join Date
    Oct 2003
    Location
    belgrade
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's better to use javascript to check if the fields in form are entered correctly.
    PHP Code:
    function checkSubmit()
    {
       if (
    document.form_name.field_name.value == "" || document.form_name.field_name.value == "some_wrong_value")
       {
          
    alert("Enter the correct data")
          
    document.form_name.field_name.focus()
          return 
    false
       

    of course add this to form tag

    <form method="post" onSubmit="return checkSubmit()">
    Vivvo CMS - Web publishing at your fingertips
    Mile voli disko, a ja belo kolumbijsko

  6. #6
    SitePoint Zealot Fizlar's Avatar
    Join Date
    Aug 2003
    Location
    Sheffield
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok cheers mate... have implemented Helge's code and have got this error

    Code:
    The following fields must be filled out:
    
    Warning: Invalid argument supplied for foreach() in /home/fizlar/public_html/vote.php on line 94

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. Change thie first lines to
    PHP Code:
    $valid true
    if(isset(
    $_POST['course'])) { 
        
    $errorFields = array(); 
    See if that helps.

    -Helge

  8. #8
    SitePoint Zealot Fizlar's Avatar
    Join Date
    Aug 2003
    Location
    Sheffield
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i put it in... but think i put it in the wrong place ... this is where i put it in

    PHP Code:
    <?php 
    // check to see if the user has submitted the form 
    if( isset( $_POST['course'] ) ) { 
        echo
    "THANK YOU"

        
    $R1 $_REQUEST['rating1']; 
        
    $R2 $_REQUEST['rating2']; 
        
    $R3 $_REQUEST['rating3']; 
        
    $R4 $_REQUEST['rating4']; 
        
    $R5 $_REQUEST['rating5']; 
        
    $R6 $_REQUEST['rating6']; 
        
    $R7 $_REQUEST['rating7']; 
        
    $R8 $_REQUEST['rating8']; 
        
    $R9 $_REQUEST['rating9']; 
        
    $R10 $_REQUEST['rating10']; 
        
    $Tx1 $_REQUEST['QUES1']; 
        
    $Tx2 $_REQUEST['QUES2']; 
        
    $Tx3 $_REQUEST['QUES5']; 
        
    $Tx4 $_REQUEST['QUES9']; 
        
    $Tx5 $_REQUEST['QUES13']; 
        
    $Tx6 $_REQUEST['QUES14']; 
        
    $Tx7 $_REQUEST['QUES16'];    
        
    $age $_REQUEST['AGE']; 
        
    $lang $_REQUEST['LANG']; 

        
    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17) VALUES (NULL,'$age','$lang','$Tx1','$Tx2','$R1','$R2','$Tx3','$R3','$R4','$R5','$Tx4','$R6','$R7','$R8','$Tx5','$Tx6','$R9','$Tx7','$R10'    )"


        
    $user "fizlar"
        
    $pass "burngr34ve"
        
    $db "fizlar2"
        
    $link mysql_connect"localhost"$user$pass ); 
        if (! 
    $link
            die (
    "could not connect to MySQL" ); 
        
    mysql_select_db ($db
            or die (
    "could not connect to $db: ".mysql_error() ); 

        
    $result mysql_query ($sql); 
        } 
         else { 

    // check to see if the user has submitted the form 
    if(isset($_POST['course'])) { 
    $valid true
    if(isset(
    $_POST['course'])) { //THIS IS WHERE I PUT IT
        
    $errorFields = array();   
     

        foreach(
    $_POST AS $key=>$value) { 
            if(empty(
    $value)) { 
                
    $valid false
                
    $errorFields[] = $key
        } 

        if(
    $valid) { 
            echo
    "THANK YOU"
            
    $R1 $_REQUEST['rating1']; 
            
    $R2 $_REQUEST['rating2']; 
            
    $R3 $_REQUEST['rating3']; 
            
    $R4 $_REQUEST['rating4']; 
            
    $R5 $_REQUEST['rating5']; 
            
    $R6 $_REQUEST['rating6']; 
            
    $R7 $_REQUEST['rating7']; 
            
    $R8 $_REQUEST['rating8']; 
            
    $R9 $_REQUEST['rating9']; 
            
    $R10 $_REQUEST['rating10']; 
            
    $Tx1 $_REQUEST['QUES1']; 
            
    $Tx2 $_REQUEST['QUES2']; 
            
    $Tx3 $_REQUEST['QUES5']; 
            
    $Tx4 $_REQUEST['QUES9']; 
            
    $Tx5 $_REQUEST['QUES13']; 
            
    $Tx6 $_REQUEST['QUES14']; 
            
    $Tx7 $_REQUEST['QUES16'];    
            
    $age $_REQUEST['AGE']; 
            
    $lang $_REQUEST['LANG']; 

            
    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17) VALUES (NULL,'$age','$lang','$Tx1','$Tx2','$R1','$R2','$Tx3','$R3','$R4','$R5','$Tx4','$R6','$R7','$R8','$Tx5','$Tx6','$R9','$Tx7','$R10'    )"


            
    $user "***"
            
    $pass "***"
            
    $db "fizlar2"
            
    $link mysql_connect"localhost"$user$pass ); 
            if (! 
    $link
                die (
    "could not connect to MySQL" ); 
                
    mysql_select_db ($db) or die ("could not connect to $db: ".mysql_error() ); 
                
    $result mysql_query ($sql); 
            } 
        echo 
    '</body></html> '
        exit; 
        } 
    }

  9. #9
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code is totally different from what I gave you in post nr.4. Try
    PHP Code:
    <?php 
    // check to see if the user has submitted the form 
    $valid true;
    if(isset(
    $_POST['course'])) { 
        
    $errorMsg = array();

        foreach(
    $_POST AS $key=>$value) {
            if(empty(
    $value)) {
                
    $valid false;
                
    $errorMsg[] = $key;
        }

        if(
    $valid) {
            echo
    "THANK YOU"
            
    $R1 $_REQUEST['rating1']; 
            
    $R2 $_REQUEST['rating2']; 
            
    $R3 $_REQUEST['rating3']; 
            
    $R4 $_REQUEST['rating4']; 
            
    $R5 $_REQUEST['rating5']; 
            
    $R6 $_REQUEST['rating6']; 
            
    $R7 $_REQUEST['rating7']; 
            
    $R8 $_REQUEST['rating8']; 
            
    $R9 $_REQUEST['rating9']; 
            
    $R10 $_REQUEST['rating10']; 
            
    $Tx1 $_REQUEST['QUES1']; 
            
    $Tx2 $_REQUEST['QUES2']; 
            
    $Tx3 $_REQUEST['QUES5']; 
            
    $Tx4 $_REQUEST['QUES9']; 
            
    $Tx5 $_REQUEST['QUES13']; 
            
    $Tx6 $_REQUEST['QUES14']; 
            
    $Tx7 $_REQUEST['QUES16'];   
            
    $age $_REQUEST['AGE']; 
            
    $lang $_REQUEST['LANG']; 

            
    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17) VALUES (NULL,'$age','$lang','$Tx1','$Tx2','$R1','$R2','$Tx3','$R3','$R4','$R5','$Tx4','$R6','$R7','$R8','$Tx5','$Tx6','$R9','$Tx7','$R10'  )"


            
    $user "****"
            
    $pass "***** "
            
    $db "***"
            
    $link mysql_connect"localhost"$user$pass ); 
            if (! 
    $link
                die (
    "could not connect to MySQL" ); 
                
    mysql_select_db ($db) or die ("could not connect to $db: ".mysql_error() ); 
                
    $result mysql_query ($sql); 
            }
        echo 
    '</body></html> ';
        exit;
        }
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
    <head> 
    <title>Feedback Form</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    </head> 

    <body><form name="BasicForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 

    My name is Fizlar and I am currently studying for my Masters degree in Information 
    Systems at the University of Sheffield, England. This questionnaire is part of 
    my on-going research to try to gain a comprehensive understanding of the problems 
    that users like yourself experience when querying a database.<br> 
    <p>&nbsp;</p>

    <?php
    if(!$valid) {
        echo 
    "The following fields must be filled out:<br />";
        foreach(
    $errorMsg AS $value) {
            echo 
    " - $value<br />\n";
        }
    }
    ?>

    <form method="post"> 
    <p>Can You Please type your age </p> 
      <input name="AGE" type="text" value="AGE" size="10"> 
    <p>What is your first language if not English</p> 
    <textarea name="LANG" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

    <p>&nbsp;</p> 

    <p>Q1, WHAT, IF ANYTHING, WOULD YOU SAY HINDERS YOUR ABILITY TO USE A COMPUTER EFFECTIVLY?</p> 
    <p> 
    <textarea name="QUES1" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

    <p>Q2, IN WHAT WAY DOES YOUR NATIVE LANGUAGE AFFECT YOUR ABILITY TO SEARCH FOR 
    A PARTICULAR PIECE OF INFORMATION? 
    <p> 
    <textarea name="QUES2" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

    <p>Q3, DO YOU THINK THIS TYPE OF SEARCHING IS HELPFUL? </p> 
    <p> 
    <input type="radio" name="rating1" value="1"> 
    1 Very Helpful<br /> 
    <input type="radio" name="rating1" value="2"> 
    2 Helpful<br /> 
    <input type="radio" name="rating1" value="3"> 
    3 Uudecided<br /> 
    <input type="radio" name="rating1" value="4"> 
    4 Unhelpful<br /> 
    <input type="radio" name="rating1" value="5"> 
    5 Very Unhelpful<br /> 
    <p>Q4, WHEN SUBMITTING YOUR FIRST QUERY, WERE THE RESULTS RETURNED SATISFACTORY 
    TO <br> 
    YOUR NEEDS?</p> 
    <p> 
    <input type="radio" name="rating2" value="1"> 
    1 Very Satisfactory<br /> 
    <input type="radio" name="rating2" value="2"> 
    2 Satisfactory<br /> 
    <input type="radio" name="rating2" value="3"> 
    3 Undecided<br /> 
    <input type="radio" name="rating2" value="4"> 
    4 Unsatisfactory<br /> 
    <input type="radio" name="rating2" value="5"> 
    5 Very Unsatisfactory 
    <p>Q5, IF NOT SATISFACTORY WHY NOT? 
    <p> 
    <textarea name="QUES5" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 
    <br /> 

    <p>Q6, HOW USEFUL DID YOU FIND THE RESULTS FROM YOUR FIRST QUERY? </p> 
    <p> 
    <input type="radio" name="rating3" value="1"> 
    1 Very Useful<br /> 
    <input type="radio" name="rating3" value="2"> 
    2 Useful<br /> 
    <input type="radio" name="rating3" value="3"> 
    3 Undecided<br /> 
    <input type="radio" name="rating3" value="4"> 
    4 Unhelpful<br /> 
    <input type="radio" name="rating3" value="5"> 
    5 Very Unhelpful<br /> 
    </p> 
    <p>Q7, DID THE RESULTS OF THE FIRST QUERY, SUPPORT YOU IN FINDING THE INFORMATION 
    YOU REQUIRED? </p> 
    <p> 
    <input type="radio" name="rating4" value="1"> 
    1 Yes<br /> 
    <input type="radio" name="rating4" value="2"> 
    2 No <br /> 
    <input type="radio" name="rating4" value="3"> 
    3 Undecided <br /> 
    </p> 
    <p>Q8, IF YOU WERE UNABLE TO RETRIEVE THE INFORMATION YOU REQUIRED FIRST TIME 
    WERE YOU <br> 
    ABLE TO RETRIEVE IT ON SUBSEQUENT SEARCHES? </p> 
    <p> 
    <input type="radio" name="rating5" value="3"> 
    1 Yes<br /> 
    <input type="radio" name="rating5" value="2"> 
    2 No<br /> 
    <input type="radio" name="rating5" value="1"> 
    3 Undecided<br /> 
    <p>Q9, WERE THERE ANY PARTS OF THE QUERYING PROCESS THAT WERE PARTICULARLY DIFFICULT 
    TO USE? 
    <p> 
    <textarea name="QUES9" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 
    <p>&nbsp; 
    <p>Q10, DO YOU FIND THIS TYPE OF DESIGN USEFUL TO YOU IN FINDING INFORMATON?</p> 
    <p> 
    <input type="radio" name="rating6" value="1"> 
    1 Very Useful<br /> 
    <input type="radio" name="rating6" value="2"> 
    2 Useful<br /> 
    <input type="radio" name="rating6" value="3"> 
    3 Undecided<br /> 
    <input type="radio" name="rating6" value="4"> 
    4 Unhelpful<br /> 
    <input type="radio" name="rating6" value="5"> 
    5 Very Unhelpful</p> 
    <p>Q11, OVERALL, HOW DID THIS WEBSITE ASSIST YOU INTO FINDING INFORMATION YOU 
    REQUIRED? </p> 
    <p> 
    <input type="radio" name="rating7" value="1"> 
    1 Very Helpful<br /> 
    <input type="radio" name="rating7" value="2"> 
    2 Useful<br /> 
    <input type="radio" name="rating7" value="3"> 
    3 Undecided<br /> 
    <input type="radio" name="rating7" value="4"> 
    4 Unhelpful<br /> 
    <input type="radio" name="rating7" value="5"> 
    5 Very Unhelpful</p> 
    <p>Q12, WAS THE LAYOUT OF THE WEBSITE CLEAR AND EASY TO NAVIGATE?</p> 
    <p> 
    <input type="radio" name="rating8" value="1"> 
    1 Yes<br /> 
    <input type="radio" name="rating8" value="2"> 
    2 No<br /> 
    <input type="radio" name="rating8" value="3"> 
    3 Undecided<br /> 
    </p> 
    <p>Q13, IF NOWHY NOT? </p> 
    <p> 
    <textarea name="QUES13" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 
    <br /> 
    <p> Q14, CAN YOU SUGGEST ANY FUTURE IMPROVEMENTS THAT COULD MAKE THE LOOK AND 
    FEEL OF THE SITE EASIER TO USE? 
    <p> 
    <textarea name="QUES14" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

    <p>Q15, COMPARED TO ANY PREVIOUS EXPERIENCE IN QUERYING FOR INFORMATION - HOW 
    DID THIS<br> 
    SEARCH ENGINE FARE IN COMPARISON?</p> 
    <p> 
    <input type="radio" name="rating9" value="1"> 
    1 Very Useful<br /> 
    <input type="radio" name="rating9" value="2"> 
    2 Useful<br /> 
    <input type="radio" name="rating9" value="3"> 
    3 Undecided<br /> 
    <input type="radio" name="rating9" value="4"> 
    4 Unhelpful<br /> 
    <input type="radio" name="rating9" value="5"> 
    5 Very Unhelpful</p> 

    <p>Q16, CAN YOU SUGGEST ANY FURTHER IMPROVEMENTS THAT WOULD ASSIST YOU IN THE 
    QUERYING PROCESS?</p> 
    <p> 
    <textarea name="QUES16" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea> 

    <p>Q17, HOW WOULD YOU RATE THIS SEARCH ENGINE ON A SCALE OF 1  5 WHERE 
    ONE IS VERY POOR AND FIVE IS EXCELLENT?</p> 
    <p> 
    <input type="radio" name="rating10" value="1"> 
    1 Very Poor<br /> 
    <input type="radio" name="rating10" value="2"> 
    2 Poor<br /> 
    <input type="radio" name="rating10" value="3"> 
    3 Undecided<br /> 
    <input type="radio" name="rating10" value="4"> 
    4 Good<br /> 
    <input type="radio" name="rating10" value="5"> 
    5 Excellentl</p> 
    <p> 
    <input type="submit" name="course" value="Submit"> 
    </p> 
    </form> 
    </body>
    </html>
    HTH

    These posts are too long

    -Helge

  10. #10
    SitePoint Zealot Fizlar's Avatar
    Join Date
    Aug 2003
    Location
    Sheffield
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i agree posts are too long!"!!

    mate i cut a pasted that previous post did not enter a single response and a msg came up 'thank you' so i dont think its validating it?!

  11. #11
    SitePoint Zealot Fizlar's Avatar
    Join Date
    Aug 2003
    Location
    Sheffield
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi i got it working... but it does not validate i cannot understand y?

    PHP Code:
    <?
    $process 
    '0';
    if(isset(
    $_POST['course'])) {
    $errors = array();
    foreach(
    $_POST as $key => $value) {
    if(empty(
    $value)) {
    $errors[] = $key;
    }
    }
    if (empty(
    $errors)){
    $R1 $_POST['rating1'];
    $R2 $_POST['rating2'];
    $R3 $_POST['rating3'];
    $R4 $_POST['rating4'];
    $R5 $_POST['rating5'];
    $R6 $_POST['rating6'];
    $R7 $_POST['rating7'];
    $R8 $_POST['rating8'];
    $R9 $_POST['rating9'];
    $R10 $_POST['rating10'];
    $Tx1 $_POST['QUES1'];
    $Tx2 $_POST['QUES2'];
    $Tx3 $_POST['QUES5'];
    $Tx4 $_POST['QUES9'];
    $Tx5 $_POST['QUES13'];
    $Tx6 $_POST['QUES14'];
    $Tx7 $_POST['QUES16'];
    $age $_POST['AGE'];
    $lang $_POST['LANG'];


    $user "***";
    $pass "*****";

    mysql_connect("localhost"$user$pass) or die('Connection Error: ' mysql_error());

    mysql_select_db('fizlar2') or die('Select Database Error: ' mysql_error());

    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, 
    Question4, Question5, Question6, Question7, Question8, Question9, Question10, 
    Question11, Question12, Question13, Question14, Question15, Question16, 
    Question17) VALUES ('', '
    $age', '$lang', '$Tx1', '$Tx2', '$R1', '$R2', '$Tx3', 
    '
    $R3', '$R4', '$R5', '$Tx4', '$R6', '$R7', '$R8', '$Tx5', '$Tx6', '$R9', '$Tx7', '$R10')";

    if (!
    $result mysql_query($sql)) {

    die(
    'Query Error: ' mysql_error());

    } else {
    echo 
    "THANK YOU";
    }
    } else {
    $process '1';
    }
    }
    if (!isset(
    $_POST['course']) || $process == '1')
    {
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Feedback Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body><form name="BasicForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    My name is Fizlar and I am currently studying for my Masters degree in Information 
    Systems at the University of Sheffield, England. This questionnaire is part of 
    my on-going research to try to gain a comprehensive understanding of the problems 
    that users like yourself experience when querying a database.<br>
    <p>&nbsp;</p>

    <? 
    if($process == '1') { 
        echo 
    "The following fields must be filled out:<br />";
        foreach(
    $errors as $form_name) {
        echo 
    $form_name "<BR>";
      }

    ?>

    <p>Can You Please type your age </p>
      <input name="AGE" type="text" value="AGE" size="10">
    <p>What is your first language if not English</p>
    <textarea name="LANG" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>

    <p>&nbsp;</p>

    <p>Q1, WHAT, IF ANYTHING, WOULD YOU SAY HINDERS YOUR ABILITY TO USE A COMPUTER EFFECTIVLY?</p>
    <p>
    <textarea name="QUES1" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>

    <p>Q2, IN WHAT WAY DOES YOUR NATIVE LANGUAGE AFFECT YOUR ABILITY TO SEARCH FOR 
    A PARTICULAR PIECE OF INFORMATION?
    <p>
    <textarea name="QUES2" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
    <p>Q3, DO YOU THINK THIS TYPE OF SEARCHING IS HELPFUL? </p>
    <p>
    <input type="radio" name="rating1" value="Very Helpful">
    1 Very Helpful<br />
    <input type="radio" name="rating1" value="Helpful">
    2 Helpful<br />
    <input type="radio" name="rating1" value="Uudecided">
    3 Uudecided<br />
    <input type="radio" name="rating1" value="Unhelpful">
    4 Unhelpful<br />
    <input type="radio" name="rating1" value="Very Unhelpful">
    5 Very Unhelpful<br />
    <p>Q4, WHEN SUBMITTING YOUR FIRST QUERY, WERE THE RESULTS RETURNED SATISFACTORY 
    TO <br> 
    YOUR NEEDS?</p>
    <p>
    <input type="radio" name="rating2" value="Very Satisfactory">
    1 Very Satisfactory<br />
    <input type="radio" name="rating2" value="Satisfactory">
    2 Satisfactory<br />
    <input type="radio" name="rating2" value="Undecided">
    3 Undecided<br />
    <input type="radio" name="rating2" value="Unsatisfactory">
    4 Unsatisfactory<br />
    <input type="radio" name="rating2" value="Very Unsatisfactory">
    5 Very Unsatisfactory
    <p>Q5, IF NOT SATISFACTORY WHY NOT?
    <p>
    <textarea name="QUES5" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
    <br />
    <p>Q6, HOW USEFUL DID YOU FIND THE RESULTS FROM YOUR FIRST QUERY? </p>
    <p>
    <input type="radio" name="rating3" value="Very Useful">
    1 Very Useful<br />
    <input type="radio" name="rating3" value="Useful">
    2 Useful<br />
    <input type="radio" name="rating3" value="Undecided">
    3 Undecided<br />
    <input type="radio" name="rating3" value="Unhelpful">
    4 Unhelpful<br />
    <input type="radio" name="rating3" value="Very Unhelpful">
    5 Very Unhelpful<br />
    </p>
    <p>Q7, DID THE RESULTS OF THE FIRST QUERY, SUPPORT YOU IN FINDING THE INFORMATION 
    YOU REQUIRED?</p>
    <p>
    <input type="radio" name="rating4" value="Yes">
    1 Yes<br />
    <input type="radio" name="rating4" value="No">
    2 No <br />
    <input type="radio" name="rating4" value="Undecided">
    3 Undecided <br />
    </p>
    <p>Q8, IF YOU WERE UNABLE TO RETRIEVE THE INFORMATION YOU REQUIRED FIRST TIME 
    WERE YOU <br>
    ABLE TO RETRIEVE IT ON SUBSEQUENT SEARCHES? </p>
    <p>
    <input type="radio" name="rating5" value="Yes">
    1 Yes<br />
    <input type="radio" name="rating5" value="No">
    2 No<br />
    <input type="radio" name="rating5" value="Undecided">
    3 Undecided<br />
    <p>Q9, WERE THERE ANY PARTS OF THE QUERYING PROCESS THAT WERE PARTICULARLY DIFFICULT 
    TO USE?
    <p>
    <textarea name="QUES9" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
    <p>&nbsp;
    <p>Q10, DO YOU FIND THIS TYPE OF DESIGN USEFUL TO YOU IN FINDING INFORMATON?</p>
    <p>
    <input type="radio" name="rating6" value="Very Useful">
    1 Very Useful<br />
    <input type="radio" name="rating6" value="Useful">
    2 Useful<br />
    <input type="radio" name="rating6" value="Undecided">
    3 Undecided<br />
    <input type="radio" name="rating6" value="Unhelpful">
    4 Unhelpful<br />
    <input type="radio" name="rating6" value="Very Unhelpful">
    5 Very Unhelpful</p>
    <p>Q11, OVERALL, HOW DID THIS WEBSITE ASSIST YOU INTO FINDING INFORMATION YOU 
    REQUIRED? </p>
    <p>
    <input type="radio" name="rating7" value="Very Helpful">
    1 Very Helpful<br />
    <input type="radio" name="rating7" value="Useful">
    2 Useful<br />
    <input type="radio" name="rating7" value="Undecided">
    3 Undecided<br />
    <input type="radio" name="rating7" value="Unhelpful">
    4 Unhelpful<br />
    <input type="radio" name="rating7" value="Very Unhelpful">
    5 Very Unhelpful</p>
    <p>Q12, WAS THE LAYOUT OF THE WEBSITE CLEAR AND EASY TO NAVIGATE?</p>
    <p>
    <input type="radio" name="rating8" value="Yes">
    1 Yes<br />
    <input type="radio" name="rating8" value="No">
    2 No<br />
    <input type="radio" name="rating8" value="Undecided">
    3 Undecided<br />
    </p>
    <p>Q13, IF NOWHY NOT? </p>
    <p>
    <textarea name="QUES13" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>
    <br />
    <p> Q14, CAN YOU SUGGEST ANY FUTURE IMPROVEMENTS THAT COULD MAKE THE LOOK AND 
    FEEL OF THE SITE EASIER TO USE? 
    <p>
    <textarea name="QUES14" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>

    <p>Q15, COMPARED TO ANY PREVIOUS EXPERIENCE IN QUERYING FOR INFORMATION - HOW 
    DID THIS<br>
    SEARCH ENGINE FARE IN COMPARISON?</p>
    <p>
    <input type="radio" name="rating9" value="Very Useful">
    1 Very Useful<br />
    <input type="radio" name="rating9" value="Useful">
    2 Useful<br />
    <input type="radio" name="rating9" value="Undecided">
    3 Undecided<br />
    <input type="radio" name="rating9" value="Unhelpful">
    4 Unhelpful<br />
    <input type="radio" name="rating9" value="Very Unhelpful">
    5 Very Unhelpful</p>

    <p>Q16, CAN YOU SUGGEST ANY FURTHER IMPROVEMENTS THAT WOULD ASSIST YOU IN THE 
    QUERYING PROCESS?</p>
    <p>
    <textarea name="QUES16" cols="60" rows="3" wrap="virtual">TYPE IN HERE</textarea>

    <p>Q17, HOW WOULD YOU RATE THIS SEARCH ENGINE ON A SCALE OF 1 – 5 WHERE 
    ONE IS VERY POOR AND FIVE IS EXCELLENT?</p>
    <p>
    <input type="radio" name="rating10" value="Very Poor">
    1 Very Poor<br />
    <input type="radio" name="rating10" value="Poor">
    2 Poor<br />
    <input type="radio" name="rating10" value="Undecided">
    3 Undecided<br />
    <input type="radio" name="rating10" value="Good">
    4 Good<br />
    <input type="radio" name="rating10" value="Excellent">
    5 Excellent</p>
    <p>
    <input type="submit" name="course" value="Submit">
    </p>
    </form>
    </body></html>
    <?}?>

  12. #12
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Fizlar.
    Here is a working solution (I think ). The way it works is that if a field is left empty (that is not allowed to) it will represent this field to the user. Any correct filled out field will be put in a hidden field.
    The fields that need to be filled out is defined in the $needed array.
    PHP Code:
    <?
    error_reporting
    (E_ALL);
    echo 
    '<a href="' $_SERVER['PHP_SELF'] . '">Reload</a>';
    $isValid true
    if(
    count($_POST) > 0) { 
        
    $needed = array('rating1''rating2''rating3''rating4''rating5''rating6''rating7''rating8''rating9''QUES1''QUES2''QUES5''QUES9''QUES13''QUES14''QUES16''AGE''LANG');
        
    $errors = array(); 
        foreach(
    $needed as $key) { 
            if(!
    array_key_exists($key$_POST) || empty($_POST[$key])) {
                
    $errors[] = $key
                
    $isValid false;
            } 
        } 
        if (
    $isValid && empty($errors)){ 
            
    $R1 $_POST['rating1']; 
            
    $R2 $_POST['rating2']; 
            
    $R3 $_POST['rating3']; 
            
    $R4 $_POST['rating4']; 
            
    $R5 $_POST['rating5']; 
            
    $R6 $_POST['rating6']; 
            
    $R7 $_POST['rating7']; 
            
    $R8 $_POST['rating8']; 
            
    $R9 $_POST['rating9']; 
            
    $R10 $_POST['rating10']; 
            
    $Tx1 $_POST['QUES1']; 
            
    $Tx2 $_POST['QUES2']; 
            
    $Tx3 $_POST['QUES5']; 
            
    $Tx4 $_POST['QUES9']; 
            
    $Tx5 $_POST['QUES13']; 
            
    $Tx6 $_POST['QUES14']; 
            
    $Tx7 $_POST['QUES16']; 
            
    $age $_POST['AGE']; 
            
    $lang $_POST['LANG']; 


            
    $user "***"
            
    $pass "*****"

            
    mysql_connect("localhost"$user$pass) or die('Connection Error: ' mysql_error()); 
            
    mysql_select_db('fizlar2') or die('Select Database Error: ' mysql_error()); 

            
    $sql "INSERT INTO QUESTION (Num_id, Age, LANG, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17) VALUES ('', '$age', '$lang', '$Tx1', '$Tx2', '$R1', '$R2', '$Tx3', '$R3', '$R4', '$R5', '$Tx4', '$R6', '$R7', '$R8', '$Tx5', '$Tx6', '$R9', '$Tx7', '$R10')"

            if (!
    $result mysql_query($sql)) { 
                die(
    'Query Error: ' mysql_error()); 
            } else { 
                echo 
    "THANK YOU"
            }
        } 

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
    <head> 
    <title>Feedback Form</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    </head> 

    <body> 
    <p>
    My name is Fizlar and I am currently studying for my Masters degree in Information 
    Systems at the University of Sheffield, England. This questionnaire is part of 
    my on-going research to try to gain a comprehensive understanding of the problems 
    that users like yourself experience when querying a database.
    </p>


    <?php if (count($_POST) < || $isValid == false) { ?>
    <form name="BasicForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    <?php
    if(!$isValid) echo "You didn't answer all of the questions.<br /> I kindly ask you to also answer the questions below.<br />"
    ?> 

    <?php if($isValid || (!$isValid && in_array('AGE'$errors))) { ?>
        <p>Can You Please type your age</p> 
        <p><input name="AGE" type="text" value="" size="10"></p>
        
       
    <?php } if($isValid || (!$isValid && in_array('LANG'$errors))) { ?>
        <p>What is your first language if not English</p> 
        <p><textarea name="LANG" cols="60" rows="3" wrap="virtual"></textarea></p>
    <?php ?>


    <p>&nbsp;</p>


    <?php if($isValid || (!$isValid && in_array('QUES1'$errors))) { ?>
        <p>Q1, WHAT, IF ANYTHING, WOULD YOU SAY HINDERS YOUR ABILITY TO USE A COMPUTER EFFECTIVLY?</p> 
        <p><textarea name="QUES1" cols="60" rows="3" wrap="virtual"></textarea></p>


    <?php } if($isValid || (!$isValid && in_array('QUES2'$errors))) { ?>
        <p>Q2, IN WHAT WAY DOES YOUR NATIVE LANGUAGE AFFECT YOUR ABILITY TO SEARCH FOR A PARTICULAR PIECE OF INFORMATION?</p> 
        <p><textarea name="QUES2" cols="60" rows="3" wrap="virtual"></textarea></p>


    <?php } if($isValid || (!$isValid && in_array('rating1'$errors))) { ?>
        <p>Q3, DO YOU THINK THIS TYPE OF SEARCHING IS HELPFUL?</p> 
        <p> <input type="radio" name="rating1" value="Very Helpful">1 Very Helpful<br /> 
            <input type="radio" name="rating1" value="Helpful">2 Helpful<br /> 
            <input type="radio" name="rating1" value="Uudecided">3 Uudecided<br /> 
            <input type="radio" name="rating1" value="Unhelpful">4 Unhelpful<br /> 
            <input type="radio" name="rating1" value="Very Unhelpful">5 Very Unhelpful
        </p>


    <?php } if($isValid || (!$isValid && in_array('rating2'$errors))) { ?>
        <p>Q4, WHEN SUBMITTING YOUR FIRST QUERY, WERE THE RESULTS RETURNED SATISFACTORY TO <br> YOUR NEEDS?</p> 
        <p> <input type="radio" name="rating2" value="Very Satisfactory">1 Very Satisfactory<br /> 
            <input type="radio" name="rating2" value="Satisfactory">2 Satisfactory<br /> 
            <input type="radio" name="rating2" value="Undecided">3 Undecided<br /> 
            <input type="radio" name="rating2" value="Unsatisfactory">4 Unsatisfactory<br /> 
            <input type="radio" name="rating2" value="Very Unsatisfactory">5 Very Unsatisfactory
        </p>


    <?php } if($isValid || (!$isValid && in_array('QUES5'$errors))) { ?>
        <p>Q5, IF NOT SATISFACTORY WHY NOT?</p> 
        <p><textarea name="QUES5" cols="60" rows="3" wrap="virtual"></textarea></p> 


    <?php } if($isValid || (!$isValid && in_array('rating3'$errors))) { ?>
        <p>Q6, HOW USEFUL DID YOU FIND THE RESULTS FROM YOUR FIRST QUERY? </p> 
        <p> <input type="radio" name="rating3" value="Very Useful">1 Very Useful<br /> 
            <input type="radio" name="rating3" value="Useful">2 Useful<br /> 
            <input type="radio" name="rating3" value="Undecided">3 Undecided<br /> 
            <input type="radio" name="rating3" value="Unhelpful">4 Unhelpful<br /> 
            <input type="radio" name="rating3" value="Very Unhelpful">5 Very Unhelpful
        </p> 


    <?php } if($isValid || (!$isValid && in_array('rating4'$errors))) { ?>
        <p>Q7, DID THE RESULTS OF THE FIRST QUERY, SUPPORT YOU IN FINDING THE INFORMATION YOU REQUIRED?</p> 
        <p> <input type="radio" name="rating4" value="Yes">1 Yes<br /> 
            <input type="radio" name="rating4" value="No">2 No <br /> 
            <input type="radio" name="rating4" value="Undecided">3 Undecided
        </p> 


    <?php } if($isValid || (!$isValid && in_array('rating5'$errors))) { ?>
        <p>Q8, IF YOU WERE UNABLE TO RETRIEVE THE INFORMATION YOU REQUIRED FIRST TIME WERE YOU <br> ABLE TO RETRIEVE IT ON SUBSEQUENT SEARCHES? </p> 
        <p> <input type="radio" name="rating5" value="Yes">1 Yes<br /> 
            <input type="radio" name="rating5" value="No">2 No<br /> 
            <input type="radio" name="rating5" value="Undecided">3 Undecided
        </p>


    <?php } if($isValid || (!$isValid && in_array('QUES9'$errors))) { ?>
        <p>Q9, WERE THERE ANY PARTS OF THE QUERYING PROCESS THAT WERE PARTICULARLY DIFFICULT TO USE? </p>
        <p><textarea name="QUES9" cols="60" rows="3" wrap="virtual"></textarea></p>


    <?php ?>


    <p>&nbsp; 


    <?php if($isValid || (!$isValid && in_array('rating6'$errors))) { ?>
        <p>Q10, DO YOU FIND THIS TYPE OF DESIGN USEFUL TO YOU IN FINDING INFORMATON?</p> 
        <p> <input type="radio" name="rating6" value="Very Useful">1 Very Useful<br /> 
            <input type="radio" name="rating6" value="Useful">2 Useful<br /> 
            <input type="radio" name="rating6" value="Undecided">3 Undecided<br /> 
            <input type="radio" name="rating6" value="Unhelpful">4 Unhelpful<br /> 
            <input type="radio" name="rating6" value="Very Unhelpful">5 Very Unhelpful
        </p> 


    <?php } if($isValid || (!$isValid && in_array('rating7'$errors))) { ?>
        <p>Q11, OVERALL, HOW DID THIS WEBSITE ASSIST YOU INTO FINDING INFORMATION YOU REQUIRED? </p> 
        <p> <input type="radio" name="rating7" value="Very Helpful">1 Very Helpful<br /> 
            <input type="radio" name="rating7" value="Useful">2 Useful<br /> 
            <input type="radio" name="rating7" value="Undecided">3 Undecided<br /> 
            <input type="radio" name="rating7" value="Unhelpful">4 Unhelpful<br /> 
            <input type="radio" name="rating7" value="Very Unhelpful">5 Very Unhelpful
        </p> 


    <?php } if($isValid || (!$isValid && in_array('rating8'$errors))) { ?>
        <p>Q12, WAS THE LAYOUT OF THE WEBSITE CLEAR AND EASY TO NAVIGATE?</p> 
        <p> <input type="radio" name="rating8" value="Yes">1 Yes<br /> 
            <input type="radio" name="rating8" value="No">2 No<br /> 
            <input type="radio" name="rating8" value="Undecided">3 Undecided<br /> 
        </p> 


    <?php } if($isValid || (!$isValid && in_array('QUES13'$errors))) { ?>
        <p>Q13, IF NO WHY NOT? </p> 
        <p><textarea name="QUES13" cols="60" rows="3" wrap="virtual"></textarea></p>


    <?php } if($isValid || (!$isValid && in_array('QUES14'$errors))) { ?>
        <p> Q14, CAN YOU SUGGEST ANY FUTURE IMPROVEMENTS THAT COULD MAKE THE LOOK AND FEEL OF THE SITE EASIER TO USE? </p> 
        <p><textarea name="QUES14" cols="60" rows="3" wrap="virtual"></textarea></p>


    <?php } if($isValid || (!$isValid && in_array('rating9'$errors))) { ?>
        <p>Q15, COMPARED TO ANY PREVIOUS EXPERIENCE IN QUERYING FOR INFORMATION - HOW DID THIS<br> SEARCH ENGINE FARE IN COMPARISON?</p> 
        <p> <input type="radio" name="rating9" value="Very Useful">1 Very Useful<br /> 
            <input type="radio" name="rating9" value="Useful">2 Useful<br /> 
            <input type="radio" name="rating9" value="Undecided">3 Undecided<br /> 
            <input type="radio" name="rating9" value="Unhelpful">4 Unhelpful<br /> 
            <input type="radio" name="rating9" value="Very Unhelpful">5 Very Unhelpful
        </p> 


    <?php } if($isValid || (!$isValid && in_array('QUES16'$errors))) { ?>
        <p>Q16, CAN YOU SUGGEST ANY FURTHER IMPROVEMENTS THAT WOULD ASSIST YOU IN THE QUERYING PROCESS?</p> 
        <p><textarea name="QUES16" cols="60" rows="3" wrap="virtual"></textarea></p>


    <?php } if($isValid || (!$isValid && in_array('rating1'$errors))) { ?>
        <p>Q17, HOW WOULD YOU RATE THIS SEARCH ENGINE ON A SCALE OF 1  5 WHERE ONE IS VERY POOR AND FIVE IS EXCELLENT?</p> 
        <p> <input type="radio" name="rating10" value="Very Poor">1 Very Poor<br /> 
            <input type="radio" name="rating10" value="Poor">2 Poor<br /> 
            <input type="radio" name="rating10" value="Undecided">3 Undecided<br /> 
            <input type="radio" name="rating10" value="Good">4 Good<br /> 
            <input type="radio" name="rating10" value="Excellent">5 Excellent
        </p> 
    <?php 

    foreach (
    $_POST AS $key=>$value) {
        if(!
    in_array($key$errors)) {
            echo 
    "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
        }
    }
    ?>
    <p> 
    <input type="submit" name="course" value="Submit"> 
    </p> 
    </form> 
    <?php ?>
    </body>
    </html>
    If anything is uncelar or is not working, don't hesitate ti ask

    -Helge


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •