Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

editing a specific record from a MYSQL database

Status
Not open for further replies.

spurs100

Technical User
Jun 5, 2002
20
GB
Hope someone can help, i am relatively new to PHP and MYSQL.

what i need to figure out is this:

I want an admin page that will pull all records from a property database and display them all on one page with two buttons next to them an edit record and delete record button

example:

id | location | description | "edit record button" delete record button"

1 | london | a nice flat | "edit" "delete"
2 | Manchester | test |
3 | test | test|
4 | test | test |
5 |test | test |

I am ok creating this page by querying the database but what i need is to be able to click on the edit button and another form appear with the data from this record populating the relevant field in the new form so i can edit that specific record. for example if i click on the edit button on row 4 the new form will appear with the data from this record populating each field.

Any thoughts?

hope one of you gurus can help

think i am confusing myself, hope someone can understand what i am trying to achieve.
 
Make sure that your field editing page is able to send the id column value to the script that updates the row in the table.

From there, it's a matter of using string concatentation to produce and UPDATE...WHERE... query from the submitted data.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Spurs100, did you ever get this problem figured out? I'm new here and a new PHP/MySQL programmer-manager and I'm having a similar problem. Adding to my problem is that the database is stored on another server, not mine, so I don't have the authority to install DaDaBIK or PHPMtAdmin and make my job easier. Instead, I have to write my own php scripts! Right now I have a script to display records in a table, delete records and insert records - that's it! If someone needs to change a field on a record they have to delete the record and re-enter it. I'd like to do something similar to you, have them check the record they want to "fix", click "Submit", and a new form opens up with editable text boxes filled with the data from that record. The individual would just go to the text box to be edited, make changes, then click "Submit" on the bottom and it would update the record.

This is not part of my full time job, I know very little about PHP or MySQL and don't use it at work, but this is for a non-profit I'm helping out. I could really use some code examples, but any and all help is appreciated!

Thanks!

Mike
 
with the edit url you send allong the id

<a href=edit.php?id=4>EDIT</a>

since you have queried it already you can use it also in the url

after that you have a form which can look something like this

Code:
<?
include $DOCUMENT_ROOT.&quot;/cgi-bin/connopen.php3&quot;;

$query=&quot;SELECT * from artisttable where id='$id'&quot;;
$rs=mysql_query($query,$conn);
$list = mysql_num_rows($rs); 
$row = mysql_fetch_array($rs); 
$arname=$row[&quot;arname&quot;];
$arspecs=$row[&quot;arspecs&quot;];


print(&quot;<html><body><table>
</td></tr>
<form action=sqlaction.php3?id=$id target=_self method=post>  
<tr><td><table>
<tr><td>Name</td><td><INPUT TYPE=\”text\” name=arname  size=50 value=$arname></td></tr>
<tr><td>Technical rider<td><TEXTAREA NAME=arspecs ROWS=10 COLS=45 WRAP=\&quot;VIRTUAL\&quot;>$arspecs</TEXTAREA></td></tr>
<tr><td><input type=Submit value=Submit name=Submit></td></tr>
</table>
</td></tr>
</TABLE>
</BODY>
</HTML>

&quot;);
[code]

in the sqlaction you can make the update statement
&quot;update propertytable set location='$location',description='$description' where id='$id'&quot;;

sorry to lazy now to change my own code. but I think you can see through that
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top