PHP display data, update and delete from database MySQL

DISPLAYING DATA

Create file named contact-list.php and the put these code :


Note : fetch_all(MYSQLI_ASSOC) = Fetch or display all data according on database column table's name see documentation.



UPDATE OR ALTER DATA

After displaying data from database, now back to contact-list.php and add some table column :



Note : num_rows = to count all records data on database.



Now create file to be filed by form to alter data, just copy contact_form.php (see on previous article) to make easier and then rename it into contact_edit_form.php.



$_GET = to get data from URL according on variable.



Copy contact-form-save.php(see on previous article) and then paste it with name contact-edit-save.php. and alter some code like these :



Now try to change for example name, change into your name or whatever :



Open your contact-list.php on browser and see if your data has changed :



DELETE DATA
To delete data from database create file contact_delete.php like these code :



After you create file contact_delete.php now open contact-list.php and then add delete column and link code





We put some javascript to avoid if user click on wrong data. And then now try to delete your data



And if successful it would be :



Now back to contact-list.php and see if data my_column_2 (id = 2) has deleted.



Finally you can insert, display, update and delete your data from database using PHP. If you want to get more information, syntax and code about PHP you can visit php.net.
Buy me a coffeeBuy me a coffee