Hi!

I want to know that how can i use buttons to update ( edit or delete) records from the php form directly into the database...

Thanks

Hi!

I want to know that how can i use buttons to update ( edit or delete) records from the php form directly into the database...

Thanks

Ok what you are trying to do it edit a table right...

If you want to display the row in the form for them to update or delete then I would advise this...

Create the form and echo the contents out.

Make sure you either have the id displayed in a text box or you have it in a hidden field.

You will need to submit buttons with two different values ( Update , Delete ) they should also have the same name and that should be it for the form.

When it gets to the document handling the request (the action on the form) we need to do something similar to this.

<?php

if( isset( $_POST['Update'] ) ) {
// Run your update query
} elseif( isset( $_POST['Delete'] ) ) {
// Delete from query
}

?>

That would be how you structure the document. If you are unclear in any way on how to update or delete rows in a MySql table then please refer to the W3Schools tutorials.

can u make it more clear what u want so i can give u the help u need

Ok what you are trying to do it edit a table right...

If you want to display the row in the form for them to update or delete then I would advise this...

Create the form and echo the contents out.

Make sure you either have the id displayed in a text box or you have it in a hidden field.

You will need to submit buttons with two different values ( Update , Delete ) they should also have the same name and that should be it for the form.

When it gets to the document handling the request (the action on the form) we need to do something similar to this.

<?php

if( isset( $_POST['Update'] ) ) {
// Run your update query
} elseif( isset( $_POST['Delete'] ) ) {
// Delete from query
}

?>

That would be how you structure the document. If you are unclear in any way on how to update or delete rows in a MySql table then please refer to the W3Schools tutorials.

I have query results in the form of html table not in the form of text or hidden fields.

hi
there are different ways to do that but most easiest and simple is as follows
first of all you have to fetch records from database and apply a link of edit in front of each record like

id name operation

1 bzzbee edit
2 tena edit

apply a link of word edit
like

<a href='update-record.php?cmd=insert&id=<?=$myrecordid?>' >Edit</edit>

this link will go on php form named as update-record.php

request the variable and apply this code

<?php

$cmd=$_REQUEST['cmd'];
$id=$_REQUEST['id'];

if( $cmd=='insert' ) 
{
$query="update mytable set name='jolly' where person_id='$id' ";
mysql_query($query);	
} 

?>

Will this work for result shown in the formo of tables??????

Yes add a link next to the table row saying edit or something like that and link it to a form with the values in a text field so you can then update or delete the entry.

yes.. josh is right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.