Updating a mysql database using php

Last week I explained how to create a link for each record to point to your update script.

By using the $id variable you output links which would pass the correct ID to the script so that it can update the database.

The syntax for an SQL statement that updates the fields in a table is: With the knowledge you now have from the lessons 19, 20 and 21, it should be quite easy to understand how the above syntax is used in practice. The code below updates Donald Duck's first name to D. The other information (last name and birthdate) are not changed.

You can try to change the other people's data by writing your own SQL statements. You have learned to insert, retrieve, delete and update a database with PHP.

First of all, we connect to the database and select the appropriate record.

$id=$_GET['id']; $username="username"; $password="password"; $database="your_database"; mysql_connect(localhost,$username,$password); $query=" SELECT * FROM contacts WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i As you can see, this code will output a standard form, but instead of having blank boxes like on the form for inserting a new record, this one already has the current information from the database inserted into it.

It's free and takes approximately one minute to sign up. PHP gives you many possibilities for adding interactivity to your web site.

updating a mysql database using php-79updating a mysql database using php-76updating a mysql database using php-20

GET indicates that the form is displayed when the user first gets to the page by pressing Edit Wish.

The current document is a part of the Creating a CRUD Application in the Net Beans IDE for PHP tutorial.

My SQL users: Click here to download the source code that reflects the project state after the previous lesson is completed.

Thus, you are actually now able to make very advanced and dynamic web solutions, where the users can maintain and update a database using forms.

If you want to see a sophisticated example of what can be made with PHP and databases, try to join our community.