looking for direction and advice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
5Systems
Forum Newbie
Posts: 4
Joined: Tue Mar 03, 2009 9:27 am

looking for direction and advice

Post by 5Systems »

Hello everyone,

I am looking for some direction and advice. I am working on a personal project to build my PHP skills, and what I am trying to do is simply create a form that pulls its data from a mySQL table, the user then inputs info and submits it to the database, simple enough, sure, but I would like to do it with loops.

I have a PHP document that builds a table called "critique_instructor" submits some questions to a database called "critique"
I have a separate PHP document that pulls those questions from the database using a loop. I also have a dropdown box to select a value.

I am looking for direction on how to go about inputing the values the user selects from the drop down that is associated with each question into my database.

I am also looking for advice if you guys think this is the correct way to go about doing it?

here is my PHP code:

Code: Select all

 
<?php
//Make a MySQL Connection
    mysql_connect("localhost", "root") or die(mysql_error());
    mysql_select_db("critique") or die(mysql_error());
 
    // Get all the data from the "critique_instructor" table
        $result = mysql_query("SELECT * FROM critique_instructor") or die(mysql_error());  
?>
 
<html>
    <head>
        <title>
            Student Critique
        </title>
    </head>
    
    <body>
        <?php echo '<h1>STUDENT CRITIQUE</h1>'; ?>
        <br>
        
        <?php echo 'In order to provide thorough training, we need your honest opinion about the training you are receiving. It 
        is not necessary to sign your name and in no way will your answers here reflect in your final grade. Your 
        frank and honest answers below will help us improve.'?>
        
        <p><?php echo '<u>Part 1 – Your instructor</u>'?>
        
        <p><?php echo 'Please rate each statement from 1 to 5, based on the following scale.'?>
        
        <p><?php echo "5………Excellent 4………Good 3………Average 2………Below Average 1………Poor"?>
        
        <form action="process.php" method="post">
            
            <!--keeps getting the next row until there are no more to get-->
            <?php while($row = mysql_fetch_array( $result )) {?>
                    <?php echo $row['id']." - ".$row['critique_question'];?>
                    
                    <select name="rating">
                        <option>5 Excellent</option>
                        <option>4 Good</option>
                        <option>3 Average</option>
                        <option>2 Below Average</option>
                        <option>1 Poor</option>
                        </select>
                     <br>
            <?php } ?>
            
 
            Use this space for any additional comments or special questions:<br>
            <textarea name="additinal_comments" rows="5" wrap="physical">
                Enter Comments Here
            </textarea>
            
            <p><input type="submit">
            
            
            
        </form>
    
    </body>
 
</html>
 
Thanks
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: looking for direction and advice

Post by AbraCadaver »

You can build an array of ratings so that you know what rating belongs to which question:

Code: Select all

<select name="rating[<?php echo $row['id']; ?>]">
Then when submitted, loop through the ratings and insert them:

Code: Select all

foreach($_POST['rating'] as $id => $rating) {
   //INSERT INTO table_name (id, rating) VALUES($id, $rating)
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: looking for direction and advice

Post by mikosiko »

5Systems wrote:....
I am also looking for advice if you guys think this is the correct way to go about doing it?

here is my PHP code:

Code: Select all

 
<?php
....
    <body>
[color=#FF0000]        <?php echo '<h1>STUDENT CRITIQUE</h1>'; ?>[/color]
        <br>
        
 [color=#FF0000]       <?php echo 'In order to provide thorough training, we need your honest opinion about the training you are receiving. It 
        is not necessary to sign your name and in no way will your answers here reflect in your final grade. Your 
        frank and honest answers below will help us improve.'?>[/color]
        
 [color=#FF0000]       <p><?php echo '<u>Part 1 – Your instructor</u>'?>[/color]
        
 [color=#FF0000]       <p><?php echo 'Please rate each statement from 1 to 5, based on the following scale.'?>[/color]
        
  [color=#FF0000]      <p><?php echo "5………Excellent 4………Good 3………Average 2………Below Average 1………Poor"?[/color]>
        
        <form action="process.php" method="post">
  .....  
    </body>
 
</html>
 
Thanks
I have a comment... why are you using php tags in the code ^^^ marked in red?... that is simple html code, therefore is not necessary to use php to display it.... that is a simple mistake... don't use php where you really don't need it.

Miko
5Systems
Forum Newbie
Posts: 4
Joined: Tue Mar 03, 2009 9:27 am

Re: looking for direction and advice

Post by 5Systems »

thanks guys I will give that a shot.
Post Reply