473,889 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to create dynamically edit table entries

34 New Member
i wish to know how to create a dinamically edit table entries .can u help me ?thanks.
Sep 29 '06 #1
11 9304
ronverdonk
4,258 Recognized Expert Specialist
As always the question is far more simple then the answer, but I'll give it a try.
The following sample is a 1-script processing 3 phases, i.e.
PHASE 1 : the db data is displayed in a table (one table row per db row) and prefixed with a 'Change' button;
PHASE 2 : the data of the selected row is shown in a <textarea> field that can be modified, along with a SAVE button;
PHASE 3 : the changed row is updated in the database.

There is no value cleansing in the sample, BUT DON'T forget it!
[PHP]<?php
/**
* Change an existing email adress in in a table row. MySql table setup:
* CREATE TABLE emailads (id INT(2) PRIMARY KEY AUTO_INCREMENT, email VARCHAR(30) DEFAULT ' ');
* Parms are passed in the $_GET or $_POST arrays, so they are extracted via $_REQUEST
*
* no parameters Display table with email adress prefixed by a Change link
* When 'Change' clicked: call this script, pass id of table entry
* $_REQUEST['PHASE'] == 2
* ['i'] : the id of the table row to be changed.
* Display table. On the spot of the to-be-changed row
* show a text input field with value from the 'old' row
* 'Save' clicked: Call this script:
* 'PHASE'(=3), 'i' (id), 'e' (new email adress)
* $_REQUEST['PHASE'] == 3
* ['i'] : the id of the row-to-change
* ['e'] : the changed email adress
* UPDATE row
*/
//--------------------------------------------------------------------------
// Open database connection (for all phases)
//--------------------------------------------------------------------------
$conn = mysql_connect(S QL_HOST, SQL_USER, SQL_PASS) or die("No connection to server: ".mysql_error() );
mysql_select_db (SQL_DB) or die("No db connection: ".mysql_error() );
//--------------------------------------------------------------------------
// Form is submitted, check parms
// PHASE 1 no parms passed
// PHASE 2 'í' passed
// PHASE 3 'i' and 'e' passed
//--------------------------------------------------------------------------
if (isset($_REQUES T['PHASE'])) {
if ($_REQUEST['PHASE'] == 2 && !isset($_REQUES T['i'])) {
echo 'Error phase 2 input parm'; exit;
}
if ($_REQUEST['PHASE'] == 3 && !isset($_REQUES T['i']) && !isset($_REQUES T['e']) ) {
echo 'Error phase 3 input parm'; exit;
}
}
//--------------------------------------------------------------------------
// PHASE 3 - update row in database
//--------------------------------------------------------------------------
if ($_REQUEST['PHASE'] == 3) {
$email = trim(strip_tags ($_REQUEST['e']));
// check content: error: issue error message and die
$sqlst = "UPDATE emailads SET email='$email' WHERE id=" . $_REQUEST['i'];
mysql_query($sq lst) or die(mysql_error ());
echo 'Entry updated<br />';
echo '<a href="change.ph p">Click here to go back</a>';
exit;
} // End PHASE 3
else {
//------------------------------------------------------------------------
// PHASE 1 and PHASE 2:
// Select data from database and show on screen
// PHASE 2: Pass email adress in HTML textbox and click SAVE
//------------------------------------------------------------------------
$sqlst = "SELECT id, email from emailads ORDER BY email";
$rows=mysql_que ry($sqlst) or die(mysql_error ());
echo '<table border="1"><tr> <th>Action</th><th>Email adress</th></tr>';
while ($row = mysql_fetch_ass oc($rows)) {
echo '<tr><td><a href="change.ph p?PHASE=2&i='.$ row['id'].'">Change</a></td>';
echo '<td>';
if ($_REQUEST['PHASE'] == 2 && $row['id'] == $_REQUEST['i'] ) {
?>
Change text and click "SAVE":
<form action="change. php" method="POST">
<textarea name="e" cols="30" rows="1"><?php echo $row['email'] ?> </textarea>
<input type="hidden" name="i" value=<?php echo $row['id'] ?> />
<input type="hidden" name="PHASE" value=3 />
<input type="submit" value="SAVE" />
</form>
<?php }
else
echo $row['email'];
echo '</td></tr>';

} // End FOREACH

echo '</table><hr />';
echo '</body></html>';

} // End ELSE ...
?>[/PHP]

Ronald :cool:
Sep 29 '06 #2
Sheau Wei
34 New Member
As always the question is far more simple then the answer, but I'll give it a try.
The following sample is a 1-script processing 3 phases, i.e.
PHASE 1 : the db data is displayed in a table (one table row per db row) and prefixed with a 'Change' button;
PHASE 2 : the data of the selected row is shown in a <textarea> field that can be modified, along with a SAVE button;
PHASE 3 : the changed row is updated in the database.

There is no value cleansing in the sample, BUT DON'T forget it!
[PHP]<?php
/**
* Change an existing email adress in in a table row. MySql table setup:
* CREATE TABLE emailads (id INT(2) PRIMARY KEY AUTO_INCREMENT, email VARCHAR(30) DEFAULT ' ');
* Parms are passed in the $_GET or $_POST arrays, so they are extracted via $_REQUEST
*
* no parameters Display table with email adress prefixed by a Change link
* When 'Change' clicked: call this script, pass id of table entry
* $_REQUEST['PHASE'] == 2
* ['i'] : the id of the table row to be changed.
* Display table. On the spot of the to-be-changed row
* show a text input field with value from the 'old' row
* 'Save' clicked: Call this script:
* 'PHASE'(=3), 'i' (id), 'e' (new email adress)
* $_REQUEST['PHASE'] == 3
* ['i'] : the id of the row-to-change
* ['e'] : the changed email adress
* UPDATE row
*/
//--------------------------------------------------------------------------
// Open database connection (for all phases)
//--------------------------------------------------------------------------
$conn = mysql_connect(S QL_HOST, SQL_USER, SQL_PASS) or die("No connection to server: ".mysql_error() );
mysql_select_db (SQL_DB) or die("No db connection: ".mysql_error() );
//--------------------------------------------------------------------------
// Form is submitted, check parms
// PHASE 1 no parms passed
// PHASE 2 'í' passed
// PHASE 3 'i' and 'e' passed
//--------------------------------------------------------------------------
if (isset($_REQUES T['PHASE'])) {
if ($_REQUEST['PHASE'] == 2 && !isset($_REQUES T['i'])) {
echo 'Error phase 2 input parm'; exit;
}
if ($_REQUEST['PHASE'] == 3 && !isset($_REQUES T['i']) && !isset($_REQUES T['e']) ) {
echo 'Error phase 3 input parm'; exit;
}
}
//--------------------------------------------------------------------------
// PHASE 3 - update row in database
//--------------------------------------------------------------------------
if ($_REQUEST['PHASE'] == 3) {
$email = trim(strip_tags ($_REQUEST['e']));
// check content: error: issue error message and die
$sqlst = "UPDATE emailads SET email='$email' WHERE id=" . $_REQUEST['i'];
mysql_query($sq lst) or die(mysql_error ());
echo 'Entry updated<br />';
echo '<a href="change.ph p">Click here to go back</a>';
exit;
} // End PHASE 3
else {
//------------------------------------------------------------------------
// PHASE 1 and PHASE 2:
// Select data from database and show on screen
// PHASE 2: Pass email adress in HTML textbox and click SAVE
//------------------------------------------------------------------------
$sqlst = "SELECT id, email from emailads ORDER BY email";
$rows=mysql_que ry($sqlst) or die(mysql_error ());
echo '<table border="1"><tr> <th>Action</th><th>Email adress</th></tr>';
while ($row = mysql_fetch_ass oc($rows)) {
echo '<tr><td><a href="change.ph p?PHASE=2&i='.$ row['id'].'">Change</a></td>';
echo '<td>';
if ($_REQUEST['PHASE'] == 2 && $row['id'] == $_REQUEST['i'] ) {
?>
Change text and click "SAVE":
<form action="change. php" method="POST">
<textarea name="e" cols="30" rows="1"><?php echo $row['email'] ?> </textarea>
<input type="hidden" name="i" value=<?php echo $row['id'] ?> />
<input type="hidden" name="PHASE" value=3 />
<input type="submit" value="SAVE" />
</form>
<?php }
else
echo $row['email'];
echo '</td></tr>';

} // End FOREACH

echo '</table><hr />';
echo '</body></html>';

} // End ELSE ...
?>[/PHP]

Ronald :cool:
I am very sorry that i still not well understand the code you had submit.
I didn't inderstant about

if (isset($_REQUES T['PHASE'])) {

Is it means i have to put the ID that i want to edit into the PHASE make it become if (isset($_REQUES T['$ID'])) ?
Sep 29 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
Nono don't do that! Read the explanation at the top of the script carefully before you change the code. As I said, this program contains 3 phases, so it passes the phase number with the GET or POST. DO NOT CHANGE THAT unless you know what you are doing! You can see in the second textline in the source code on what table this code is working and was tested.
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE emailads (id INT(2) PRIMARY KEY AUTO_INCREMENT, email VARCHAR(30) DEFAULT ' ');
  2.  
And the value of column 'id' is passed as i= and the value of column email is passed as e= in the $_REQUEST array in this script.

If you have a different table, as I am sure you do, you must change the column names in the script accordingly. In this sample it changes column 'email' and uses the 'id' column to pass and select the information from the database.

If you still have problems, show me the table columns you use and I will show you how to change it.

Ronald :cool:
Sep 29 '06 #4
Sheau Wei
34 New Member
Nono don't do that! Read the explanation at the top of the script carefully before you change the code. As I said, this program contains 3 phases, so it passes the phase number with the GET or POST. DO NOT CHANGE THAT unless you know what you are doing! You can see in the second textline in the source code on what table this code is working and was tested.
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE emailads (id INT(2) PRIMARY KEY AUTO_INCREMENT, email VARCHAR(30) DEFAULT ' ');
  2.  
And the value of column 'id' is passed as i= and the value of column email is passed as e= in the $_REQUEST array in this script.

If you have a different table, as I am sure you do, you must change the column names in the script accordingly. In this sample it changes column 'email' and uses the 'id' column to pass and select the information from the database.

If you still have problems, show me the table columns you use and I will show you how to change it.

Ronald :cool:
This is the code and table column i use. When use click to EDIT then will edit the one row of information display. Hope that u can teach me how to do it
<?php

// check if id is passed to this routine
if (isset($_GET['id'])) {
// if yes: remove harmful tags and save the passed id in variable $id
$id = strip_tags($_GE T['id']);

//required file for database connection
require("config .php");
echo "<table border='1'>";
// construct SQL statement
$sql = mysql_query("SE LECT *FROM iteminfomation WHERE ID='$id'");
$sql1=mysql_que ry("SELECT NameOfTools,Bra nd FROM listofitem WHERE ID='$id'");
$information1=m ysql_fetch_arra y($sql1);
$information=my sql_fetch_array ($sql);

echo "<table border='1'>";
echo "<tr><td>NamaOf Tools</th><td>Brand</th><td>Date</th>Quantity</th><td Price</th><td>Price</th></tr>";


echo"<tr><td>{$ information1['NameOfTools']}</td>
<td>{$informati on1['Brand']}</td>
<td>{$informati on['Date']}</td>
<td>{$informati on['Quantity']}</td>
<td>{$informati on['Price']}</td>
</table>";
}
Sep 29 '06 #5
ronverdonk
4,258 Recognized Expert Specialist
With the sample code I provided you with you can update 1 row in 1 table. It does not allow you to update 2 rows in 2 tables!
Seeing your display
Expand|Select|Wrap|Line Numbers
  1. echo"<tr><td>{$information1['NameOfTools']}</td>
  2. <td>{$information1['Brand']}</td>
  3. <td>{$information['Date']}</td>
  4. <td>{$information['Quantity']}</td>
  5. <td>{$information['Price']}</td>
  6. </table>";
  7. }
  8.  
what column of what table would you like to change?

Ronald :cool:
Sep 29 '06 #6
Sheau Wei
34 New Member
With the sample code I provided you with you can update 1 row in 1 table. It does not allow you to update 2 rows in 2 tables!
Seeing your display
Expand|Select|Wrap|Line Numbers
  1. echo"<tr><td>{$information1['NameOfTools']}</td>
  2. <td>{$information1['Brand']}</td>
  3. <td>{$information['Date']}</td>
  4. <td>{$information['Quantity']}</td>
  5. <td>{$information['Price']}</td>
  6. </table>";
  7. }
  8.  
what column of what table would you like to change?

Ronald :cool:
ok. let say i want to edit the table of iteminformation column of Quantity.Is it imposiblle to change data in two table?
Sep 29 '06 #7
ronverdonk
4,258 Recognized Expert Specialist
You replace the 'email' column and value in the sample by the name and value of the column you want to change.

What else you request is, according to me, beyond the scope of this forum. This forum is to help people help themselves e.g. 'show the way', provide samples, give guidance, point to documentation, even educate a bit, etc. But it is not intended to write full-fledged applications.

In my opinion, the sample I provided here is tested and works for updating one column value in a selected db row via an html table. If you want to extend that function to more columns or even 2 tables, go ahead. I will help you when you have questions.

Ronald :cool:
Sep 29 '06 #8
Sheau Wei
34 New Member
You replace the 'email' column and value in the sample by the name and value of the column you want to change.

What else you request is, according to me, beyond the scope of this forum. This forum is to help people help themselves e.g. 'show the way', provide samples, give guidance, point to documentation, even educate a bit, etc. But it is not intended to write full-fledged applications.

In my opinion, the sample I provided here is tested and works for updating one column value in a selected db row via an html table. If you want to extend that function to more columns or even 2 tables, go ahead. I will help you when you have questions.

Ronald :cool:
i am really want to help myself.but i really cant understand wat u mean. I had replace the column i want to change but the error occur saying that

Notice: Undefined index: PHASE in C:\server\Apach e2\htdocs\New1. php on line 45

i dont understand why .
I replace like below.please forgive me because i cannot get what u had teach me.

if (isset($_REQUES T['PHASE'])) {
if ($_REQUEST['PHASE'] == 2 && !isset($_REQUES T['i'])) {
echo 'Error phase 2 input parm'; exit;
}
if ($_REQUEST['PHASE'] == 3 && !isset($_REQUES T['i']) && !isset($_REQUES T['e']) ) {
echo 'Error phase 3 input parm'; exit;
}
}
//--------------------------------------------------------------------------
// PHASE 3 - update row in database
//--------------------------------------------------------------------------
if ($_REQUEST['PHASE'] == 3) {
$NameOfTools = trim(strip_tags ($_REQUEST['e']));
// check content: error: issue error message and die
$sqlst = "UPDATE listofitem SET NameOfTools='$N ameOfTools' WHERE id=" . $_REQUEST['i'];
mysql_query($sq lst) or die(mysql_error ());
echo 'Entry updated<br />';
echo '<a href="change.ph p">Click here to go back</a>';
exit;
} // End PHASE 3
else {
Sep 29 '06 #9
ronverdonk
4,258 Recognized Expert Specialist
Is your id field in your db row numeric or character? rEMEMBER: In the example it is a numeric, so the sql statement defined is something like "... WHERE id=. $_REQUEST['i']". When it is a character field, you must enclose this id in quotes, such as
Expand|Select|Wrap|Line Numbers
  1. $sqlst = "UPDATE listofitem SET NameOfTools='$NameOfTools' WHERE id='" . $_REQUEST['i']."'";
If the id is numeric, you must have changed the code in some other place. In that case, please show it exactly as you have tested it.

Ronald :cool:
Sep 29 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
10814
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would then like that, when clicking the LinkButton, the user can be navigated to another page, carrying a variable. I would like to use server.transfer method instead of QueryString as I don't want the carried variable to be visible for the user.
10
3333
by: nick_faye | last post by:
Hi guys, i'm still a newbie in using MS Access and in VB programming. I am using DAO connection from my VB to access the entries on my MS Access table. I am having trouble in editting and deleting entries from my table because it becomes slower and slower when my table is getting bigger and bigger. What I am doing right now is get the ID of the entry to be editted/deleted and I have to loop from first entry until I found the right ID...
0
1141
by: goitz | last post by:
Im looking for a way to dynamically create a table and append a text box to it using a list of information from a database eg> display a results of a select statment then add a text box--> field1 field2 textbo datagrids only allow clicking a button to edit a field, too much clicking to edit multiple fields required Please help
0
2743
by: neoteny2 | last post by:
I need MS Access to automatically create reports/subreports based on specific criteria. I am building a database in Access 2003 with different locations/sites. I have the "sites" table created containing site info, including an empty field for "date". I also have a report format already created displaying the site info. I need Access to ask the user for a date, calculate three additional dates using the entered date (adding or subtracting...
2
5672
by: news reader | last post by:
Hi, Does anoone of you know if there is already a simple application doing something like this. I would enhance / tune the missing features, but would like to avoid to start from scratch or to start from something, that has far too many features and is difficult to setup.
3
9244
by: dauphian | last post by:
Greetings, I have a user control, that I will need to display on a specific page based on the number of records in database: I have to query a site table to get the number of entries as well as a specific column field for each entry. I then pass that to the user control to grab a specific set of information from another table and display.
11
3204
by: bharathmngl | last post by:
now iam trying to add rows dynamically into the table when i click "ADD ROW" button. It should also have the option to delete the selected row. So Please help me to find code.... And also please tell me how to add textarea and radiobutton in to the dynamically created rows.. Here is my code; <html> <head> <title>Untitled Document</title>
7
4880
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio buttons and check box. I am adding two radio buttons once for a row.Now my problem is the radio buttons in all the rows that added dynamically are behaving as same group i.e when i am selecting a radio button in second row,radio button in first row...
1
4918
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can get the value from a text box with resides inside the first panel (out side of panel that is...
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9805
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5825
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6021
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4248
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.