Question:
PHP- edit a row from a MySQL table?
anonymous
2008-06-24 03:11:05 UTC
hi guys. i stucked with this part of my assignment. i have a table with 4 columns created in MySQL database. the user can view the table in browser and a link saying "edit data". i want to allow the user to edit (update/delete) this table. by clicking on the link the user goes to another page that has a form with two buttons; one to update data and the other one to delete data from database. I dont know how to let the user to view a particular row in this form to delete or update it. im not allowed to use checkbox to select a row to be edited.
thank you .
Four answers:
anonymous
2008-06-24 03:43:58 UTC
To allow a user to select an individual row you could append the row id to a hyperlink. For example the link on one page could be www.example.com/edit.php?id=1



When a user clicks on this link they will be taken to the edit.php page. On this page you can retrieve the id from the URL using REQUEST:



$id = $_REQUEST['id']



When you know the id you can then use this to select the necessary record from the database using the following code:



SELECT * FROM table WHERE id = $id;



If you then store the record details into an array you can place the details into a form by referencing the data in the "value" attribute of a textbox. For example:







A user could then edit the details in the form and click a button that will run an update statement or you could have a button which runs a delete query
balu
2008-06-24 03:18:38 UTC
You can follow this approach if you are



1) displaying the records in a table row

2) You have "edit data" link against each row



All you have to do is, fetch the record id (primary key or any other unique identification id) along with the data and pass it as a parameter to the next page along with "edit data" link. You can fetch the same record in the next page and allow the user to edit/delete the same.



For example:

edit data



Let me know if this is what you are looking for or something else.
anonymous
2008-06-24 03:58:34 UTC
Heres the code to print out your data in a Table.

you will need to edit some info however, as a programmer u should know ; )



I have upload the codes to my website answers always cut away some of the codes..



heres the address

http://www.runescapegod.com/ans.txt



if you can any queries you can contact me at

admin@runescapegod.com
plute
2016-10-19 13:22:18 UTC
i understand the way you experience. once you place up your kind, only pull the row identity from the positioned up records then use a query like this: $rowID = $_POST['row_id']; $call = $_POST['call']; $content cloth = $_POST['content cloth']; $sq. = "replace table_name SET call = '$call ' , content cloth = '$content cloth' the place identity = '$rowID' shrink one million"; $result = mysql_query($sq.) or die(mysql_error()); in case you wanna loop via extra rows only use a for loop accurately.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...