Skip to main content

Updating Multiple Rows in MySQL using PHP


There are so many tutorials on how to update one (1) record at a time. But only few tutorial on how to update multiple rows at once. I dedicate this tutorial to my 3rd year students. Save the following code as select.php:
".mysql_error()); $i = 0; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo "\n"; while ($students = mysql_fetch_array($result)) { echo ''; echo ""; echo ""; echo ""; echo ''; ++$i; } echo ''; echo ""; echo ''; echo ""; echo '
'; ?>
Save the following code as update.php:

"; ++$i; } ?>
Import the SQL Statement into your database called "students" using PHPMyAdmin included in the zip file.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Submitted byAnonymous (not verified)on Tue, 10/04/2011 - 09:33

thanks alot sir for this solution. It has been a problem on my mind for quite some time now. Another big problem i have is how to create a line graph using data from a database such that when the database is altered, the graph automatically updates itself. if you can offer any help at all, please do so by sending me a mail via ; [email protected] Thank you.

Submitted byAnonymous (not verified)on Tue, 10/04/2011 - 13:39

can you create a directory system using php? pls.. i need this. my prof. give us a code does not working thats why dnt know how to do that system. so pls. can you create a directory system. any directory like telephone directory, employee directory etc. anything that you can do. pls. help me. :((

Submitted byAnonymous (not verified)on Wed, 10/05/2011 - 04:08

Hi sir,,hahaha,,,,thank you gd,,,na kwa ko na kag na try ko na man butang sakun system,,lamat gd nga madamu,,hahaha,,uhm,,,,ang prob nlg is that,on how to add regular load to a specific students,,,rehus sg enrollment system,ke sa sbg ang system ko ga add course individualy,,,t,,it realy takes tym for the admin to input such data,,hmmpt,,ask ko tne sir panu mag add regular load sg students para mpahapus ang ubra sg admin or the check ko cmu sir if mag balik ko sa skul...kag thank you gd liwat sa codes...hahah....,,,,by:Smool Eztremos

Submitted byAnonymous (not verified)on Wed, 11/23/2011 - 05:11

Thanks a lot, this was very helpful!

Submitted bybeni (not verified)on Fri, 02/03/2012 - 03:55

As you wrote there is no many tutorials on this subject,
helped me very much.

Submitted byAnonymous (not verified)on Tue, 01/22/2013 - 14:25

U have helped me a lot..I was really looking for the this for the last one week..Ur code is simple and very very dramatic ...Lot of thanks,

Submitted byAnonymous (not verified)on Tue, 03/12/2013 - 05:38

Thanks a lot !!! Sir you have helped me a lot.

Submitted byAnonymous (not verified)on Tue, 05/07/2013 - 23:15

It has been very useful and with a clear code, thank you !!!!!

Submitted byAnonymous (not verified)on Sun, 06/09/2013 - 05:49

Thank you very much, your code helped me a lot, thanks.

Submitted byprem_123 (not verified)on Wed, 08/07/2013 - 12:03

can i change the text box which is going to be updated to combo box with my own option values
means i want combo box in place of text box,. with the pre filled option and some some my provided options

Submitted byEvans Mwambije (not verified)on Fri, 09/20/2013 - 23:39

It very nice code dear

Submitted byAmir Weinberger (not verified)on Wed, 06/25/2014 - 17:46


Thanks for the great code.

How does it work with SELECT fields?
When I fill the SELECT field with table data, I don't know how to pass the selected value to the processing page. I get there a blank value

Thanks again!

Submitted bysanjay sharan (not verified)on Tue, 07/19/2016 - 09:48

I found this site really great. Giving solutions without any pomp and shows which other websites actually doing.
Great! cannot getting appropriate word to praise

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.