954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Edition example

Hello every one,
I have made the insertion, viewing part of the database, but want to have an edition part too, could anyone plz kindly guide me, how it is possible to have edition part too?

NOTE;
I am using PHP 5..., MySQl 5... , and Apache Server

tanha
Posting Whiz in Training
218 posts since Aug 2007
Reputation Points: 8
Solved Threads: 1
 

Be more specific.

Do you insert data with forms ?

- Mitko Kostov

MitkOK
Junior Poster
142 posts since Jul 2007
Reputation Points: 59
Solved Threads: 12
 

Thanks for replying,
Yes, I insert the data through the HTML form into the database, and now I want to have edition part too, but I dont know how to manage that

tanha
Posting Whiz in Training
218 posts since Aug 2007
Reputation Points: 8
Solved Threads: 1
 

So, only thing you have to do is to select records from the database and put them in the forms ( value="..." ). After submit you update the database with the new values.

Example :

<?php

// connect to SQL server and select DB
// ..
// your query will select to edit record by id if you have one

$query = "SELECT name, phone, mail from table where id='$id' ";

$result = mysql_query($query, $link);

$row = mysql_fetch_array($result);

?><form action="edit.php" method="POST">
<input type="text" name="name" value="<?php echo $row['name']; ?>">
<input type="text" name="phone" value="<?php echo $row['phone']; ?>">
<input type="text" name="mail" value="<?php echo $row['mail']; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="submit" value="Edit">
</form>


edit.php

<?php

// connect to DB server and select DB
....
// validate form data
// ...

$query = "UPDATE table SET name='$_POST[name]', phone='$_POST[phone]', name='$_POST[mail]' WHERE id='$_POST[id]' ";

// ...

?>

-Mitko Kostov

MitkOK
Junior Poster
142 posts since Jul 2007
Reputation Points: 59
Solved Threads: 12
 

Thanks very much, I will try to go through your code, and then if still had problem, posting here...

tanha
Posting Whiz in Training
218 posts since Aug 2007
Reputation Points: 8
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You