Connecting Tech Pros Worldwide Forums | Help | Site Map

Displaying data just added into database

Newbie
 
Join Date: Sep 2007
Posts: 27
#1: Oct 16 '09
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 Thumbnails
picture-1.jpg  

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,096
#2: Oct 17 '09

re: Displaying data just added into database


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
Newbie
 
Join Date: Sep 2007
Posts: 27
#3: Oct 17 '09

re: Displaying data just added into database


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 .
Newbie
 
Join Date: Sep 2007
Posts: 27
#4: Oct 18 '09

re: Displaying data just added into database


Hey Dan
Did you give up on me?

Sarah
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,963
#5: Oct 18 '09

re: Displaying data just added into database


Quote:

Originally Posted by sarah aziz View Post

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:

Expand|Select|Wrap|Line Numbers
  1. <!-- myhtmlform.html -->
  2. <form action="myphppage.php" method="post">
  3.   <input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" />
  4. </form>
  5.  
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.
Newbie
 
Join Date: Sep 2007
Posts: 27
#6: Oct 18 '09

re: Displaying data just added into database


Thanks Mark for your reply it worked but what if i want to return the field disabled how is that achievable?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,963
#7: Oct 18 '09

re: Displaying data just added into database


Using the same logic as above (check the POST index exists, and do some action based on the result). See input element attribute - disable.
Newbie
 
Join Date: Sep 2007
Posts: 27
#8: Oct 18 '09

re: Displaying data just added into database


It doesn't seem to work Mark
here is my code
index.php
Expand|Select|Wrap|Line Numbers
  1. $sql_role_name = mysql_query("SELECT Role_ID,Role_name,Role_real_name,email FROM 5novRoles WHERE Group_ID = ".$result["Group_ID"]) 
  2.                     or die (mysql_error());
  3. while ($result_role_name = mysql_fetch_array($sql_role_name))
  4. {
  5.     echo '<form action="getData.php?" method="get">
  6.           <tr>
  7.                     <input type="hidden" name="id" value="'.$result_role_name["Role_ID"].'" />
  8.                     <td align="right" width="200">'.$result_role_name['Role_name'].'</td>
  9.                     <td align="left" width="auto" ><input class="sd" type="text" name="r" value="'.$result_role_name['Role_real_name'].'"></input></td>
  10.                     <td align="left" width="200" ><input class="sd" type="text" name="email" value="'.$result_role_name['email'].'"></input></td>
  11.                     <td align="right" width="100px"><button type="submit" class="submit" style="margin-right:0px" />Valider</td>
  12.          </tr>
  13.          </form>';
  14. }
submit.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('connect_to_DB.php');
  3.  
  4. $role_real_name = $_GET['r'];
  5. $role_id = $_GET['id'];
  6. $role_email = $_GET['email'];
  7.  
  8. //echo $role_id;
  9. //echo $role_real_name;
  10.  
  11. mysql_query("UPDATE 5novRoles SET Role_real_name ='".$role_real_name.
  12.             "' , email ='".$role_email.
  13.             "'WHERE Role_ID =  ".$role_id)  or die (mysql_error());
  14.  
  15. header('Location:index.php');
  16. ?>
What should i do when return to index.php to disable the field that holds the data retrieved
Newbie
 
Join Date: Sep 2007
Posts: 27
#9: Oct 19 '09

re: Displaying data just added into database


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

Expand|Select|Wrap|Line Numbers
  1.    $sql_role_name = mysql_query("SELECT Role_ID,Role_name,Role_real_name,email FROM 5novRoles WHERE Group_ID = ".$result["Group_ID"]) 
  2.                     or die (mysql_error());
  3. while ($result_role_name = mysql_fetch_array($sql_role_name))
  4. {
  5. if ($result_role_name['Role_name'] != "" )
  6. {
  7. if($result_role_name['Role_real_name'] != "" )
  8. {
  9. echo '<form name="test" action="php/update.php?" method="get">
  10.           <tr>
  11.                     <input type="hidden" name="id" value="'.$result_role_name["Role_ID"].'" />
  12.                     <td align="right" width="200">'.$result_role_name['Role_name'].'</td>
  13.                     <td align="left" width="auto" ><input class="sd" type="text" id="r" name="r" disabled value="'.$result_role_name['Role_real_name'].'"></input></td>
  14.                     <td align="left" width="200" ><input class="sd" type="text" name="email" disabled value="'.$result_role_name['email'].'"></input></td>
  15.                     <td align="right" width="100px"><button type="submit" disabled/>Valider</td>
  16.          </tr>
  17.          </form>';
  18.         // echo '<tr><td colspan="3">'.$result_role_name['Role_real_name'].'</td></tr>';
  19. }
  20. else if ($result_role_name['Role_real_name'] == "" )
  21. {
  22.     echo '<form name="test" action="php/update.php?" method="get">
  23.           <tr>
  24.                     <input type="hidden" name="id" value="'.$result_role_name["Role_ID"].'" />
  25.                     <td align="right" width="200">'.$result_role_name['Role_name'].'</td>
  26.                     <td align="left" width="auto" ><input class="sd" type="text" id="r" name="r"></input></td>
  27.                     <td align="left" width="200" ><input class="sd" type="text" name="email"></input></td>
  28.                     <td align="right" width="100px"><button type="submit" />Valider</td>
  29.          </tr>
  30.          </form>';
  31. }
  32. }
  33. }
Reply

Tags
php