Displaying data just added into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarah aziz
    New Member
    • Sep 2007
    • 31

    Displaying data just added into database

    Hello Guys
    I attached a picture of my layout
    Here in steps what am doing and what is missing
    1- In the empty field i write some data that is inserted in the database when i click on the Valider button i submit onto another page and then return to this page

    1-The problem is when i return to same page i want to display the data that was just added into the database.
    How is that achievable ?
    2-Second problem i want when click on the button at bottom called (créer) to add an empty field like the above one.How can i do that ?

    Thanks in advance
    Attached Files
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    1. Store the values in a hidden field or in an array in session as well, then when you get back to this page (based on some other conditions as well) display the values in the session. But if you want to display the more recently added records, you have to do this with SQL based on your condition. (ie if User A inserts 5 records, then user B sees those records when he logs on)

    2. You can do this with Javascript. see innerHTML and add element.

    Cheers,





    Dan

    Comment

    • sarah aziz
      New Member
      • Sep 2007
      • 31

      #3
      Hey Dan
      Thanks for your reply.
      What i need to do has nothing to do with the database.
      I meant to say after i submit the data i submitted appear and the empty fields downwards remain to enter data How can i do that submit into different page or what

      Thanks again .

      Comment

      • sarah aziz
        New Member
        • Sep 2007
        • 31

        #4
        Hey Dan
        Did you give up on me?

        Sarah

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by sarah aziz
          Hey Dan
          Did you give up on me?

          Sarah
          Hi, Sarah.

          If you're submitting the form, I expect you'll be using POST or GET (method type for form). If so, you'll be able to retrieve these values from the aforementioned arrays in PHP. Consider the following:

          Code:
          <!-- myhtmlform.html -->
          <form action="myphppage.php" method="post">
            <input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" />
          </form>
          In the value attribute of the input element we run some PHP code that says if this form element is available (already been submitted) in the POST array, print its value out. Otherwise, do nothing.

          Does this help?

          Mark.

          Comment

          • sarah aziz
            New Member
            • Sep 2007
            • 31

            #6
            Thanks Mark for your reply it worked but what if i want to return the field disabled how is that achievable?

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Using the same logic as above (check the POST index exists, and do some action based on the result). See input element attribute - disable.

              Comment

              • sarah aziz
                New Member
                • Sep 2007
                • 31

                #8
                It doesn't seem to work Mark
                here is my code
                index.php
                Code:
                $sql_role_name = mysql_query("SELECT Role_ID,Role_name,Role_real_name,email FROM 5novRoles WHERE Group_ID = ".$result["Group_ID"]) 
                	   		     or die (mysql_error());
                while ($result_role_name = mysql_fetch_array($sql_role_name))
                {
                	echo '<form action="getData.php?" method="get">
                		  <tr>
                					<input type="hidden" name="id" value="'.$result_role_name["Role_ID"].'" />
                					<td align="right" width="200">'.$result_role_name['Role_name'].'</td>
                					<td align="left" width="auto" ><input class="sd" type="text" name="r" value="'.$result_role_name['Role_real_name'].'"></input></td>
                					<td align="left" width="200" ><input class="sd" type="text" name="email" value="'.$result_role_name['email'].'"></input></td>
                					<td align="right" width="100px"><button type="submit" class="submit" style="margin-right:0px" />Valider</td>
                		 </tr>
                		 </form>';
                }
                submit.php
                Code:
                <?php
                include('connect_to_DB.php');
                
                $role_real_name = $_GET['r'];
                $role_id = $_GET['id'];
                $role_email = $_GET['email'];
                
                //echo $role_id;
                //echo $role_real_name;
                
                mysql_query("UPDATE 5novRoles SET Role_real_name ='".$role_real_name.
                		    "' , email ='".$role_email.
                		    "'WHERE Role_ID =  ".$role_id)  or die (mysql_error());
                
                header('Location:index.php');
                ?>
                What should i do when return to index.php to disable the field that holds the data retrieved
                Last edited by Dormilich; Oct 18 '09, 05:11 PM. Reason: Please use [code] tags when posting code

                Comment

                • sarah aziz
                  New Member
                  • Sep 2007
                  • 31

                  #9
                  This is what i have done so it would help other people
                  index.php

                  Code:
                     $sql_role_name = mysql_query("SELECT Role_ID,Role_name,Role_real_name,email FROM 5novRoles WHERE Group_ID = ".$result["Group_ID"]) 
                  	   		     or die (mysql_error());
                  while ($result_role_name = mysql_fetch_array($sql_role_name))
                  {
                  if ($result_role_name['Role_name'] != "" )
                  {
                  if($result_role_name['Role_real_name'] != "" )
                  {
                  echo '<form name="test" action="php/update.php?" method="get">
                  		  <tr>
                  					<input type="hidden" name="id" value="'.$result_role_name["Role_ID"].'" />
                  					<td align="right" width="200">'.$result_role_name['Role_name'].'</td>
                  					<td align="left" width="auto" ><input class="sd" type="text" id="r" name="r" disabled value="'.$result_role_name['Role_real_name'].'"></input></td>
                  					<td align="left" width="200" ><input class="sd" type="text" name="email" disabled value="'.$result_role_name['email'].'"></input></td>
                  					<td align="right" width="100px"><button type="submit" disabled/>Valider</td>
                  		 </tr>
                  		 </form>';
                  		// echo '<tr><td colspan="3">'.$result_role_name['Role_real_name'].'</td></tr>';
                  }
                  else if ($result_role_name['Role_real_name'] == "" )
                  {
                  	echo '<form name="test" action="php/update.php?" method="get">
                  		  <tr>
                  					<input type="hidden" name="id" value="'.$result_role_name["Role_ID"].'" />
                  					<td align="right" width="200">'.$result_role_name['Role_name'].'</td>
                  					<td align="left" width="auto" ><input class="sd" type="text" id="r" name="r"></input></td>
                  					<td align="left" width="200" ><input class="sd" type="text" name="email"></input></td>
                  					<td align="right" width="100px"><button type="submit" />Valider</td>
                  		 </tr>
                  		 </form>';
                  }
                  }
                  }
                  Last edited by Dormilich; Oct 19 '09, 09:54 AM. Reason: Please use [code] tags when posting code

                  Comment

                  Working...