0

I need some Help, i made this Code and when someone do the form the name they filled in have to be written to the table.

So if someone typed: "Jay Adamsen" in the name field. and Checked "Bar" and then choose "10:00 - 11:00" then the form will write it to the right place. and that works perfectly :)

But when another guy types: "Jack Carlson" In the name field and Checked "Bar" and then choose "11:00 - 12:00" then the code will delete "Jay Adamsen" and write the new name to the right box.
enter image description here enter image description here enter image description here

Here is my Code:

<?php
        $navn = $_REQUEST['navn'];
    $bar = $_POST['barorindgang'];
    $tidspunkt = $_POST['klokken'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body {
        width: 950px;
        margin-left: auto;
        margin-right: auto;


}

#Banner {
        width: 950px;
        height: 200px;
        margin-left: auto;
        margin-right: auto;
        margin-top: 5px;
        margin-bottom: 10px;


}
.tekst {
        text-align: center;
}
.link1 {
        height: 50px;
        width: 237px;
        float: left;
}
.link2 {
        height: 50px;
        width: 237px;
        float: left;
}
.link3 {
        height: 50px;
        width: 237px;
        float: left;
}
.link4 {
        height: 50px;
        width: 237px;
        float: left;
}
#vagt {
        float: left;
        margin-top: 10px;
        background-color: #C3C;
        width: 950px;
}
.text {
        text-align: center;
        font-size: 38px;

}
table,th,td {
        margin-left: auto;
        margin-right: auto;
        border: 1px solid black;
        background-color: #FF6;
        margin-bottom: 10px;

}
.form {
        margin-left: 35px;
        width: 100%;
}
</style>

<title>Ghetto Bash</title>
</head>

<body>

<div id="Banner">
<a href="index.html"><img src="pics/ghettobashbanner.jpg"></a>
</div>

<div id="bar">
        <div class="link1"><a href="index.html"><img src="pics/forside.jpg"></a> </div>
    <div class="link2"><a href="vagtplan.html"><img src="pics/vagtplan.jpg"></a> </div>
    <div class="link3"><a href="billetter.html"><img src="pics/biletter.jpg"></a></div>
    <div class="link4"><a href="billeder.html"><img src="pics/billeder.jpg"></a></div>
</div>

<div id="vagt">
  <p class="text">Vagtplan</p>
  <table width="93%" height="354" cellpadding="1">
          <tr>
            <th width="25%" scope="col">TIDER</th>
            <th width="38%" scope="col">BAR</th>
            <th width="37%" scope="col">INDGANG</th>
      </tr>
          <tr>
            <th scope="row">10:00 - 11:00</th>
            <td>
        <center>
        <?php  
        if ($bar == "bar" && $tidspunkt == "10:00") {          
            print $navn;      
        }        
        ?>
        </center>
                </td>
            <td>
        <center>
        <?php  
        if ($bar == "indgang" && $tidspunkt == "10:00") {          
            print $navn;      
        }        
        ?></center>
        </td>
      </tr>
          <tr>
            <th scope="row">11:00 - 12:00</th>
            <td>        <center><?php  
        if ($bar == "bar" && $tidspunkt == "11:00") {          
            echo $navn;      
        }        
        ?></center></td>
            <td>        <center><?php  
        if ($bar == "indgang" && $tidspunkt == "11:00") {          
            echo $navn;      
        }        
        ?></center></td>
      </tr>
          <tr>
            <th scope="row">12:00 - 13:00</th>
            <td>        <center><?php  
        if ($bar == "bar" && $tidspunkt == "12:00") {          
            echo $navn;      
        }        
        ?></center></td>
            <td>        <center><?php  
        if ($bar == "indgang" && $tidspunkt == "12:00") {          
            echo $navn;      
        }        
        ?></center></td>
      </tr>
          <tr>
            <th scope="row">13:00 - 14:00</th>
            <td>        <center><?php  
        if ($bar == "bar" && $tidspunkt == "13:00") {          
            echo $navn;      
        }        
        ?></center></td>
            <td>        <center><?php  
        if ($bar == "indgang" && $tidspunkt == "13:00") {          
            echo $navn;      
        }        
        ?></center></td>
      </tr>
          <tr>
            <th scope="row">14:00 - 15:00</th>
            <td>        <center><?php  
        if ($bar == "bar" && $tidspunkt == "14:00") {          
            echo $navn;      
        }        
        ?></center></td>
            <td>        <center><?php  
        if ($bar == "indgang" && $tidspunkt == "14:00") {          
            echo $navn;      
        }        
        ?></center></td>
      </tr>
  </table>
  <center>
  <form method="post" action="vagtplan.html">
  Navn: <input type="text" name="navn" id="navn" required="required"/><br />
  Bar: <input type="radio" name="barorindgang" value="bar" id="bar" required="required" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Indgang: <input type="radio" name="barorindgang" value="indgang" id="indgang" required="required" /><br />

  Klokken: <select name="klokken">
  <option value="10:00">10:00 - 11:00</option>
  <option value="11:00">11:00 - 12:00</option>
  <option value="12:00">12:00 - 13:00</option>
  <option value="13:00">13:00 - 14:00</option>
  <option value="14:00">14:00 - 15:00</option>
  </select>
  <br />
  <input type="submit" value="Send" />
  </form>
  </center>

</div>
</body>
</html>
John Conde
  • 217,595
  • 99
  • 455
  • 496

4 Answers4

1

This is standard function. If you wish to save the previous entries, they have to be stored in Database or text files on the server.

Nawed Khan
  • 4,393
  • 1
  • 10
  • 22
  • Can u please Help me? and if u know how to do it? Can u also help me so it says an error, if a box in the table already has some characters in it? – BechGameplay May 14 '14 at 14:33
  • Can U please Help me? i made a Database so now the database save the user options... But how do i make so the names that they type in will be in the table forever? – BechGameplay May 14 '14 at 16:06
  • STOP constantly repeating your comments on every single answer. – patricksweeney May 14 '14 at 17:01
1

When you re-enter the name it kind of refresh your page by which you lose your previous values on that page. you can use database to store value or create a xml or json file or you can store values in session.

An other option is by using AJAX then you can submit without losing your previous values.

Community
  • 1
  • 1
Harry
  • 44
  • 6
  • Can U please Help me? i made a Database so now the database save the user options... But how do i make so the names that they type in will be in the table forever? – BechGameplay May 14 '14 at 16:06
  • The name that user will enter will stay in database forever until you delete it if user is able to store it in database. You have to post another question where you are getting problem in your new code. – Harry May 14 '14 at 16:15
0

Keep a temporary variable to print the value in table since it is changing every time.

    **Here is my Code:**

    <?php
    $navn = $_REQUEST['navn'];
    $bar = $_POST['barorindgang'];
    $tidspunkt = $_POST['klokken'];

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <style type="text/css">
                body {
                    width: 950px;
                    margin-left: auto;
                    margin-right: auto;


                }

                #Banner {
                    width: 950px;
                    height: 200px;
                    margin-left: auto;
                    margin-right: auto;
                    margin-top: 5px;
                    margin-bottom: 10px;


                }
                .tekst {
                    text-align: center;
                }
                .link1 {
                    height: 50px;
                    width: 237px;
                    float: left;
                }
                .link2 {
                    height: 50px;
                    width: 237px;
                    float: left;
                }
                .link3 {
                    height: 50px;
                    width: 237px;
                    float: left;
                }
                .link4 {
                    height: 50px;
                    width: 237px;
                    float: left;
                }
                #vagt {
                    float: left;
                    margin-top: 10px;
                    background-color: #C3C;
                    width: 950px;
                }
                .text {
                    text-align: center;
                    font-size: 38px;

                }
                table,th,td {
                    margin-left: auto;
                    margin-right: auto;
                    border: 1px solid black;
                    background-color: #FF6;
                    margin-bottom: 10px;

                }
                .form {
                    margin-left: 35px;
                    width: 100%;
                }
            </style>

            <title>Ghetto Bash</title>
        </head>

        <body>

            <div id="Banner">
                <a href="index.html"><img src="pics/ghettobashbanner.jpg"></a>
            </div>

            <div id="bar">
                <div class="link1"><a href="index.html"><img src="pics/forside.jpg"></a> </div>
                <div class="link2"><a href="vagtplan.html"><img src="pics/vagtplan.jpg"></a> </div>
                <div class="link3"><a href="billetter.html"><img src="pics/biletter.jpg"></a></div>
                <div class="link4"><a href="billeder.html"><img src="pics/billeder.jpg"></a></div>
            </div>

            <div id="vagt">
                <p class="text">Vagtplan</p>
                <table width="93%" height="354" cellpadding="1">
                    <tr>
                        <th width="25%" scope="col">TIDER</th>
                        <th width="38%" scope="col">BAR</th>
                        <th width="37%" scope="col">INDGANG</th>
                    </tr>
                    <tr>
                        <th scope="row">10:00 - 11:00</th>
                        <td>
                            <center>
                                <?php  
                                if ($bar == "bar" && $tidspunkt == "10:00") {    
                                $navn_bar_10 = $navn;
                                print $navn_bar_10;      
                                }        
                                ?>
                            </center>
                        </td>
                        <td>
                            <center>
                                <?php  
                                if ($bar == "indgang" && $tidspunkt == "10:00") {   
                                $navn_indgang_10 = $navn;
                                print $navn_indgang_10;      
                                }        
                                ?></center>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">11:00 - 12:00</th>
                        <td>        <center><?php  
                                if ($bar == "bar" && $tidspunkt == "11:00") {  
                                $navn_bar_11 = $navn;        
                                echo $navn_bar_11;      
                                }        
                                ?></center></td>
                        <td>        <center><?php  
                                if ($bar == "indgang" && $tidspunkt == "11:00") {          
                                $navn_indgang_11 = $navn;
                                echo $navn_indgang_11;      
                                }        
                                ?></center></td>
                    </tr>
                    <tr>
                        <th scope="row">12:00 - 13:00</th>
                        <td>        <center><?php  
                                if ($bar == "bar" && $tidspunkt == "12:00") {          
                                $navn_bar_12 = $navn;                
                                echo $navn_bar_12;      
                                }        
                                ?></center></td>
                        <td>        <center><?php  
                                if ($bar == "indgang" && $tidspunkt == "12:00") {          
                                $navn_indgang_12 = $navn;                 
                                echo $navn_indgang_12;      
                                }        
                                ?></center></td>
                    </tr>
                    <tr>
                        <th scope="row">13:00 - 14:00</th>
                        <td>        <center><?php  
                                if ($bar == "bar" && $tidspunkt == "13:00") {          
                                $navn_bar_13 = $navn;                 
                                echo $navn_bar_13;     
                                }        
                                ?></center></td>
                        <td>        <center><?php  
                                if ($bar == "indgang" && $tidspunkt == "13:00") {          
                                $navn_indgang_13 = $navn;                 
                                echo $navn_indgang_13;           
                                }        
                                ?></center></td>
                    </tr>
                    <tr>
                        <th scope="row">14:00 - 15:00</th>
                        <td>        <center><?php  
                                if ($bar == "bar" && $tidspunkt == "14:00") {          
                                $navn_bar_14 = $navn;                 
                                echo $navn_bar_14;         
                                }        
                                ?></center></td>
                        <td>        <center><?php  
                                if ($bar == "indgang" && $tidspunkt == "14:00") {          
                                $navn_indgang_14 = $navn;                 
                                echo $navn_indgang_14;         
                                }        
                                ?></center></td>
                    </tr>
                </table>
                <center>
                    <form method="post" action="vagtplan.html">
                        Navn: <input type="text" name="navn" id="navn" required="required"/><br />
                        Bar: <input type="radio" name="barorindgang" value="bar" id="bar" required="required" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Indgang: <input type="radio" name="barorindgang" value="indgang" id="indgang" required="required" /><br />

                        Klokken: <select name="klokken">
                            <option value="10:00">10:00 - 11:00</option>
                            <option value="11:00">11:00 - 12:00</option>
                            <option value="12:00">12:00 - 13:00</option>
                            <option value="13:00">13:00 - 14:00</option>
                            <option value="14:00">14:00 - 15:00</option>
                        </select>
                        <br />
                        <input type="submit" value="Send" />
                    </form>
                </center>

            </div>
        </body>
    </html>

Also for better approach you can maintain db and retrieve values from db .

database-setup

php-form-processing

mysql_insert_php.htm

Hitesh
  • 4,098
  • 11
  • 44
  • 82
  • Can U please Help me? i made a Database so now the database save the user options... But how do i make so the names that they type in will be in the table forever? – BechGameplay May 14 '14 at 16:05
0

HTTP is stateless. This means that, when a user submits the form, the form submission has no knowledge of any form submissions that may have happened previously - unless you take steps to save that data. In your example, your form is only displaying data that the user just submitted; it's not storing that data anywhere, nor is it retrieving data that other people submitted and prepopulating the tables. And as the administrator of that server, you will have no knowledge of what people have submitted, because it's not being stored anywhere.

At the very least, your form handler should save the submitted data (probably to a database, though you could work up a solution with a flat file if you really had to). And then your form display logic will need to retrieve the saved data and display it.

Also, I strongly recommend you look into using foreach to loop over your time slots, rather than duplicating your code so much. It'll make the code a lot smaller and easier to maintain.

Brian Kendig
  • 2,452
  • 2
  • 26
  • 36
  • Can U please Help me? i made a Database so now the database save the user options... But how do i make so the names that they type in will be in the table forever? – BechGameplay May 14 '14 at 16:07
  • The PHP that renders your form will need to retrieve the user options that you saved in the database, and then prepopulate the form values with that data. There are many examples of this out there; for example: http://stackoverflow.com/questions/7030551/simplifying-php-forms-that-pre-populate-with-dabase-data-and-error-check-so-act – Brian Kendig May 14 '14 at 17:44