Day 13
Welcome to the Final day of learning sessions of ‘PHP In 15 Days - Guaranteed’ Training Course. This is really going to be a fantastic day. You will learn today few last but not least techniques, which are often used and with this we will complete almost everything which you need to build a basic fully functional web-application. So, today we will complete 13 days of this training course.From tomorrow that is day14 we will start building Admin Panel with Login System. So, what we are going to learn today is:
· Delete Data
· Update Data
· Delete And Update data Through PHP And User Form
Delete Data:
There can be several reasons, we need to delete data from database. In this situation we use delete query. Once any data or record is deleted, the action is almost irreversible. So, before using this query or action, you should be confident and know what you are doing. Right now we are in our database, within our users’ table and inside command-prompt of MySQL and here we are going to write delete query. Delete from and then table name.
DELETE FROM `users`
This query can be executed as it is. This query is a complete delete query, but this query will delete all the records of users table. We don’t want to run this, instead, we need a query to delete some specific record. So, in the same manner, we use WHERE clause which we used in select query. No difference at all. So, let’s just put userID equals to 1.
DELETE FROM `users` WHERE userID = 1
So, this is our full delete query and this will delete one record from users table where userID is 1.We can add as many parameters as we want as we did in select query. Let’s make this record more specific and put, ‘AND name equals to Saud’ or you can also say ‘not equals to Saud’. So, this portion of WHERE clause is going to find that specific record and it’s found will delete that otherwise will return empty query.
DELETE FROM
`users` WHERE userID = 1 AND name != ‘Saud’
Let’s run this query, click, ‘Go’, and you can see 0 rows deleted message. As you know, we have name equals to Saud where userID is 1 in the table. Now let’s try one more time and this time in where clause just put userID equals to 1.
DELETE FROM
`users` WHERE userID = 1
So, let’s run and it obviously deleted the record where it finds the userID equals to 1. Let’s browse our table again and you can see, first record with userID 1 has been deleted. Let’s insert it back through insert option of PHPMyAdmin.
You can specify any kind of identity of that particular record you want to delete, and MySQL will search for that and it will delete all of those records which contains all the matching values. Let’s create another delete query and in where clause, we are going to delete all the records where salt field is not empty. It means all the records in the users’ table, where the salt field has some data, will be deleted. So, before the execution of this query just browse the table to see where the salt column has some thing. So, here you can see only one record and that is userID 4 has some data in salt field. So, obviously this will be deleted.
DELETE FROM
`users` WHERE salt != ‘’
Let’s run this query now. Click, Go, 1 row deleted. Let’s go to the table and refresh and you can see record having userID 4 has been deleted. I am going to insert it again using Insert option of PHPMyAdmin, just put some data and click GO and it’s inserted again. So, in short, you can delete any record or set of records by specifying them, using WHERE clause or any clause we used in select query. This is all up to you what criteria you put forward to search the record and then delete it.
Update data:
Now to update data we need to write and execute the update query. What we do here, we specify some criterial for the record to be searched and when that kind of record is searched the update portion of the query executes within one single query. So, it’s very much like the delete query. So, in SQL command prompt just click the UPDATE tab and you can see the select query. Just remove all of this. Now we have the basic syntax. UPDATE, keyword, and then table name and that is ‘users’ as we want to update some record within our users table and then, ‘SET’, keyword. After this we write a field or column name in which we want to update data and then equals sign and then the value with which the existing data will be replaced. Let’s just put Jamie here. Here is our update query. But we haven’t yet specified which record we want to update. So, if we run this query this will change all the names to Jamie within this table. Obviously we never want it. So, let’s specify a record. To specify we can use any clause we used in select query tutorial, and so, we can update that specific record or set of records. Let’s put ‘WHERE userID equals to 2’
UPDATE `users` SET `name` = ‘Jamie’ WHERE name =
‘James’ AND `userID` = 2
So, this update query will update name field of only one record where userID is 2. Let’s make it more specific and tell that name = ‘James’ and put ‘AND’ between them. So, let’s run this query, click, ‘Go’ and 1 row affected. Our update query has updated the record where userid is 2 and name was equal to James. Let’s brows the table and refresh, and you can see Jamie here.
Let’s paste the query again, in command prompt and change the name to Jamie and userID to 5, so, this query will not affect any rows as we don’t have such kind of data where the userID is 5 and name is Jamie.
UPDATE `users` SET `name` = ‘Jamie’ WHERE name =
‘Jamie’ AND `userID` = 5
Click, ‘Go’ and here we get, 0 rows affected. It means such kind of data was not found. Now let’s just change by specifying where name equals to ‘Jamie’ and we want to set the name back to ‘James’, hit Go, 1 row affected. It means the record was found and updated where the name was Jamie.
UPDATE `users` SET `name` = ‘James’ WHERE name =
‘Jamie’
Let’s go to the table hit refresh and you can see we have James back in the name column for one specific record. You can see some names are repeated here. Let’s update more than one record with a single query. Set name to Troy where ever MySQL finds the James, so, this query will make changes for all those records where it will find the name James.
UPDATE `users` SET `name` = ‘Troy’ WHERE name =
‘James’
Run it. And here you can see, 2 rows affected. So, two records have been updated. Let’s have a look at the table. Refresh it, and you can see name of userID 2 updated to Troy as well as for userID 15.
Let’s try another update query one last time, let’s write set name to ‘Raffel’ WHERE the name is ‘Stone Cold’, so this query will find all the records having names as ‘Stone Cold’ and will change all of them to Raffel. But here we want the change in onlyfew of the records. Let’s just make changes to the records where IDcan either be 11 or 13 but the name should be updated only if the name is Stone Cold. So, we are going to apply two conditions here mainly. First, query will select records which have the name ‘Stone Cold’ only and secondly, it will select from these selected records only those, where the userID is 11 or 13.
Let’s append our query to gain this functionality, with, ‘and’ userID should be equals to 11 and now, we need to write ‘or’ because we need to change any or all of the userIDs we are defining. So, let’s put ‘or’ userID equals to 13.
UPDATE `users` SET `name` = ‘Raffel’ WHERE name =
‘Stone Cold’ AND `userID` = 11 OR `userID` = 13
Now, we have written a complete update query. Let’s run it now. You can see 2 rows affected. Now, let’s go to the table and verify the query execution. Don’t forget to refresh the table to see the latest data. You can see here, two records updated where the name was ‘Stone Cold’ and userID was either 11 or 13. But no changes were made to all the other records, having same name ‘Stone Cold’, they still have the same old data with them. So, this is how you can run update queries and update records you want, by selecting some specific records.
Update, Delete Records Using PHP:
Now, we have learnt how to write update and delete query. Now let’s fit these in PHP script and try to update and delete data through this script. So, I have created a new file “update_delete_data_by_php.php”. First we will write all the stuff we always write to run a MySQL query. Between these double quotes now, let’s write the update query. Update and then table name i.e. users and then SET, name equals to ‘Peter’ and then username equals to ‘peters’ and at the end we need to specify in which record we want to update data. So, let’s make these changes in the record having userID 1.
UPDATE users SET name = ‘Peter’, ‘username’ = ‘peters’
WHERE userID = 1
So, this is our query which is going to update the name and username fields’ for the record having userID 1. Let’s run it and obviously we wouldn’t be able to run it as we did not make connection with MySQL. Let’s just include connection file and run the script again.Here we have an error in our query, just before username. So, let’s see what it is. And you can see here we put single quotes around the field name which is not legal, we can just put back-tech or not, no any other punctuation marks here. Let’s just correct these and put ` (back-tech) for all.
UPDATE `users` SET `name` = ‘Peter’, `username` =
‘peters’ WHERE `userID` = 1
Let’s refresh the browser and here we go. Query has been executed and the data should have been updated. Let’s go to users table and browse it, and you can see our first record having userID 1 has been updated.
Now just comment out update query as we are going to write and execute only delete query now. So, let’s write the whole structure to execute a query within PHP. So, here between double quotes we are ready to write delete query. Delete from users, the table name, as we want to delete a record from users table. We will not run this query right now because this query will delete all the records from users table. So, we need to specify a record, let’s just have a look at table. So, here a record having userID 3, let’s specify this in our query. So, where userID equals to 3.
DELETE FROM users WHERE userID = 3
Let’s run this query by refreshing our browser, and let’s go to the table and refresh it. You can see, the record having userID 3 has been deleted. Really simple and straight forward. We have studied all of this in detail before.
Now we want to create a user interface from where, our website administrators can update and delete any record. Seems complicated but it’s really not. So, the first thing we need is to create a PHP file where we will display all the records of users table and then with each record we will display links to update and delete that specific record.Let’s create a file ‘update_delete_users.php’. In this file we need to display all the users with their information in a table which we have already created in day12, so, let’s use that. Just copy all the stuff and paste that in here. Let’s require the connection file. Now, we must check the output in the browserto see if everything is working fine. So, everything is fine, we can see the data. We can display other information of users too, like, joined, so, create another ‘th’ and Joined and below here we need to get this joined field too from result array. Make a variable $joined and let’s just echo it below here. Let’s refresh the browser and you can see, joined field’s data is visible now. Now, the actual thing is to create links to update and delete specific data. Let’s create another td here. Just write Update and then a non breaking space and then delete. Here we need another th too for this table data, let’s give the heading ‘Action’. Now, let’s browse this to see the user interface. You can see it’s getting developed. Although we haven’t yet made, update and delete words as links. Let’s do it now.
Just put a i.e. the link tag around both of these Update and Delete words. Now, you can see by browsing we have made these as links. These are click able, but not taking us anywhere as we did not provide any URLs. Now, let’s put the link of our file we created before and that is ‘update_delete_data_by_php.php’ and you know, now these both links will take us to this page, but on that page we don’t have any instructions coming from here, what to do. So, we need to send some data along with URL to let us know what to do when request arrives. To send some data along with this URL put a question mark and then update equals to true. Do same thing with delete, you can either put true here or 1 and that is the same thing.
<a href=" update_delete_data_by_php.php?update=true"> Update </a>
<a href="update_delete_data_by_php.php?delete=true"> Delete </a>
So, this URL will guide us either update link was clicked or delete.
Now let’s go to ‘update_delete_data_by_php.php’. First of all comment this delete query as we don’t want to run it every time we refresh this page. Now, we want to check here what type of data is coming to this page or which request is coming to this page. From ‘update_delete_users.php’ page we are sending some data enclosingin a URL.Please recall get and post method we discussed in our Form Submission tutorial. We set the data for, get method and we say it as we set the get. Every data that we send through a URL is always sent by Get Method. Now we want to get the data from this $_GET super global array.
So, let’s create a conditional statement if, $_GET super global array is set, it means if get has been set and available, only then proceed further and echo $_GET[‘update’], so let’s see what it shows. Just watch it here at the bottom, update equals true, let’s click it and you can see it’s echoing the value we set in the get. But if we click delete it will display an error, rightly so, undefined index, update. So, we need to develop this code to handle these requests. So, let’s create another if condition here that if, isset, $_GET and i.e. update and $_GET[‘update’] equals to true only then proceed. So, here just give the comment, update record and elseif , in here just copy paste the above statement and change it to delete, so if delete is set and is equals to true then we will execute something here. For now, just echo ‘We will update record.’ And in elseif section just echo ‘we will delete record’.
if(isset($_GET)){
if(isset($_GET['update']) &&$_GET['update'] == true) {
//Update Record
echo ‘We will update record.’;
}
elseif(isset($_GET['delete']) &&$_GET['delete'] == true) {
//Delete Record
echo ‘We will delete record.’;
}
}
Now, let’s browse this page again, refresh the browser.Let’s click on update and you can see update message displayed.Now let’s get back to the record page and click delete and we get the delete message displayed. So, now we are successfully getting the information, from URL about what to do on each button clicked.
Now if you watch these URLs carefully, you can see there is no information about the specific data but only update or delete. We must send some information about the specific record to perform any of these actions on it. So, let’s add another information in this URL and that is userID and make it equals to and here we will echo the userID of this specific record we got in this code above. Just copy this whole new code and paste it in here for delete URL too. So now, we are sending userID withineach URL along with the action.
<a href="update_delete_data_by_php.php?update=true&userID=<?=$userID?>"> Update </a>
<a href="update_delete_data_by_php.php?delete=true&userID=<?=$userID?>"> Delete </a>
Now just go back to the browser and on users listing page refresh it, and just pay a little attention while hovering, just keep looking below here while I hover the cursor on the links, and you can see the specific userID at the end of the URL with each record. Now just remove this echo from here and get userID from $_GET super-global array. This userID is the name we defined in users listing file within URL here. So, we are calling this userID, in get super global array. We can define it whatever we like. Let’s change it to id and in delete URL too, so if we want to get it’s value, we need to specify id here.
<a href="update_delete_data_by_php.php?update=true&id=<?=$userID?>"> Update </a>
<a href="update_delete_data_by_php.php?delete=true&id=<?=$userID?>"> Delete </a>
Now we can make a variable for this value and let’s just echo it out. Do the same thing for elseif section, that is for delete link. Just put a phrase ‘Update record’ to help us understand what’s going on. Put a br tag too and br tag in delete section too.
if(isset($_GET)){
if(isset($_GET['update']) &&$_GET['update'] == true) {
//Delete Record
echo'Update record.';echo '<br>';
echo$id = $_GET['id'];
}
elseif(isset($_GET['delete']) &&$_GET['delete'] == true) {
//Delete Record
echo'We will Delete the record.';echo '<br>';
echo$id = $_GET['id'];
}
}
Let’s check this functionality in the browser. Just refresh the page and click any update, you can see ‘Update Record’ message along with its userID and that is 1. Get back to the page again and click delete of any record, you can see concerned userID with delete message. You can verify this for any record and you will get the concerned userID with a message of concerned activity.
So, finally, we are ready to write delete code. We will first complete the delete section and then we will complete our update code. As, there is a twist in update code coming up. I am trying my best to use as much simple and easy approach as possible. So that, you can understand everything well enough. I don’t want to mess up all the things together. Let’s start coding in delete section. You can see everything is set here we have the concerned userID to which we need to delete as well as we know when to run this query. So, now, just bring our commented query here in this section. Let’s just cut it and paste right in this section. This is the ID for which we need to delete the record and is sent by user listing page. So, instead of hard quoted userID let’s put this variable, in delete query. So, now our query will work in connection with the request. When the delete link will be clicked, a concerned userID will be sent through URL and it will be grabbed here and will be supplied to the query and delete query will be executed and eventually delete the record. Let’s just put this query execution in a variable qr, and if this query is executed we will echo ‘Record having id’ and then concatenate$id we received above, and then concatenateit with a space and was successfully deleted. Otherwise was not deleted, please try again.
elseif(isset($_GET['delete']) &&$_GET['delete'] == true) {
//Delete Record
//echo 'We will Delete the record.';echo '<br>';
$id = $_GET['id'];
$qr = mysql_query("
DELETE FROM `users` WHERE `userID` = $id
") or die(mysql_error().'Error at Line: '.__LINE__);
if($qr){
echo 'Record having id '. $id .' was successfully deleted.';
} else{
echo 'Record having id '. $id .' was not deleted. Please try again.';
}
}
So, now we have completed our code to delete the record for which the user or admin will click the delete button. Let’s check this functionality now. Go to the users listing page i.e. update_delete_users.php. If we click on update, same old process, shows a message with userID. Now let’s try clicking delete link, so, this first record will be deleted. Just click delete, and you can see the delete message, ‘Record having id 1 was successfully deleted.’ It’s obvious now, that our script has deleted the record successfully. Let’s have a look at users table, refresh, and there is no record with userID 1, let’s go to user listing page, refresh it, and first user having userID 1 is gone. Just one more time, try to delete record having userID 2, click here, and, it’s also deleted easily. Let’s go back to users listing page and you can see record with userID 2 also gone. Go to the users table, refresh and you can see userID 2 is no more. So, this is how we create the delete functionality usingPHP.
Now, let’s move on and write the code to update records. This is the patch of code where we verified the update request and getting userID on which we need to perform update action. We can, offcourse, create the whole functionality to update here, but I don’t feel you will be comfortable with that. So, I am just moving this portion of code to another file. We need to change the path in the update link as well. So, let’s create a new PHP file, ‘update_form’. So, we will write some of the update code here. Basically this is going to hold the form, where user will provide update data for the record. Let’s just create it right now and you will understand what’s going on. Let’s cut our update code from previous file and bring that here, and from here just remove this, ‘else’, and rest of everything is fine now.
Below is the data we cut from update_delete_data_by_php.php file and took to the new update_form.php
if(isset($_GET['update']) &&$_GET['update'] == true){
//Update record
echo'Update the record.';echo'<br>';
$id = $_GET['id'];
}
Below is the code from where we removed ‘else’ only.
if(isset($_GET['delete']) &&$_GET['delete'] == true) {
//Delete Record
//echo 'We will Delete the record.';echo '<br>';
$id = $_GET['id'];
$qr = mysql_query("
DELETE FROM `users` WHERE `userID` = $id
") or die(mysql_error().'Error at Line: '.__LINE__);
if($qr){
echo 'Record having id '. $id .' was successfully deleted.';
} else{
echo 'Record having id '. $id .' was not deleted. Please try again.';
}
}
Now, you can see we want to receive data from $_GET super global array, to update the specific record here in update_form.php file. So, let’s go to the users listing page and here we will put the update_form.php instead of update_delete_data_by_php.php within this link. So, now when someone will click this link this will take to the update_form.php page, rest of all will remain same. Let’s go to update_form.php page to checkif code is fine. Here, if the ‘get’ is set, only then the message and userID will be echoed. So, let’s get back to the browser and check it. Refresh the users listing page, now, click on update and that’s what we expected. You can see the same old update message with concerned userID, and if you look carefully in the URL address bar, you can see we have been sent to update_form.php page. So, this is the first step we wanted to achieve. As everything is fine till now, let’s move ahead. So, when admin will click update, he would get a form to fill for relevant fields he wants to update. Let’s close and open PHP tags here, so, we can create a form here.
Instead of creating a new form, we can just copy and past the registration form, which we created on day 11 for user registration. Just copy this from here and paste it in update_form.php file. Let’s just change the heading to ‘Update Record’ and value of input button to show ‘Update’ and comment out this message at the top. Now, let’s try to click the update button and see what happens. Just refresh the users listing page and click update and now you can see a form is displayed here with the heading ‘Update Record’ and button with Update written on it.
update_form.php page
if(isset($_GET['update']) &&$_GET['update'] == true){
//Update record
//echo 'Update the record.';echo '<br>';
$id = $_GET['id'];
?>
<h2> Update Record </h2>
<form method="post" action="update_in_db.php">
Name: <input type="text" name="name" value="<?=$name?>"><br>
User Name: <input type="text" name="username" value="<?=$username?>"><br>
Password: <input type="text" name="password" value="<?=$password?>"><br>
<input type="hidden" name="userID" value="<?=$id?>">
<input type="submit" value="Update">
</form>
<?php
}
But you can see these fields of update form are empty. How user would know, which data is already there in database and which I need to update. So, first thing we need to do, is, provide previously recorded data of this particular record to the admin who wants to update this. So, let’s get back to the update_form.php file and let’s write a query here which is going to be a select query. This query will select only the record for the userID which has been requested to update. So, “Select all from users where userID equals to $id” this is the variable we created up here.
$id = $_GET['id'];
mysql_query("
SELECT * FROM users WHERE userID = $id
") or die(mysql_error().'Error at Line: '.__LINE__);
So, this query will select the only one record which id we already have. Let’s fetch the results in array and get the data from that array. Just check if the query has been run and if it is only then we will get the data. Put the selected data as an array in $result. Now we can get the data of field name, username and password. Now, let’s put all these in variables. $name, $username and $password.
$qr = mysql_query("
SELECT * FROM users WHERE
userID = $id
") or die(mysql_error().'Error at Line: '.__LINE__);
if($qr){
$result = mysql_fetch_assoc($qr);
$name = $result['name'];
$username = $result['username'];
$password = $result['password'];
}
Now, we have all the data which is in database for this userID, let’s just echo these in their concerned form fields as a value of the field. Echo name in name field, username in username field and password in password form field. Also, change this type password to text so user might be able to see what the password was before. Also, we need the connection file, just copy and paste it in here.
update_form.php page
require_once '../day10/connection_with_db.php';
if(isset($_GET['update']) &&$_GET['update'] == true){
//Update record
//echo 'Update the record.';echo '<br>';
$id = $_GET['id'];
$qr = mysql_query("
SELECT * FROM users WHERE userID = $id
") or die(mysql_error().'Error at Line: '.__LINE__);
if($qr){
$result = mysql_fetch_assoc($qr);
$name = $result['name'];
$username = $result['username'];
$password = $result['password'];
}
?>
<h2> Update Record </h2>
<form method="post" action="update_in_db.php">
Name: <input type="text" name="name" value="<?=$name?>"><br>
User Name: <input type="text" name="username" value="<?=$username?>"><br>
Password: <input type="text" name="password" value="<?=$password?>"><br>
<input type="submit" value="Update">
</form>
<?php
}
Let’s try this functionality. Let’s go to the browser and go to users listing page, refresh it. Just click update for any of the records, and here we have all the data for this particular record, fetched directly from the databaseand displayed in the form fields. Now, I am sure you can feel the user-friendliness of this form. Now the user would know exactly what he needs to change or not. Let’s get back to the user listing page, and now we will click this 11 number record, you can remember the record displayed here. Just click it and you can see same data is displayed in the concerned fields of the form. We can verify also, by going to the users table and you can see record userID 11, all the same data here.
Only one final step is remaining, that is we need to submit this form and update the data submitted through this form. So, here in action let’s put a file name, update_in_db.php.
<form method="post" action="update_in_db.php">
We want to send data of this form to this file and on this file we will process this data and then run an update query that will eventually update the record. So, let’s create this file now. Let’s paste the connection link at the top of this file. So, now the data of this form will be sent to our new file. Let’s just check whether it’s working, by just echoing ‘Update the record finally.’. Go back to the update form page, just refresh it once and click ‘Update’ button. You can see we are at the update_in_db.php page with a message we echoed out.
Here within our form we need to submit the userID as well of the record, for which we willupdate data. So, let’s create an input field, with the type hidden and name it whatever you want, for now just keep it userID and give it the value of the id we want to work on. So, just echo the $id here. Same we get here.
<form method="post" action="update_in_db.php">
Name: <input type="text" name="name" value="<?=$name?>"><br>
User Name: <input type="text" name="username" value="<?=$username?>"><br>
Password: <input type="text" name="password" value="<?=$password?>"><br>
<input type="hidden" name="userID" value="<?=$id?>">
<input type="submit" value="Update">
</form>
Let’s go to the update form page and refresh and now, if we look at the source code of this page, you can see we are sending userID along with this form data. Now we have all setup here. Let’s go to the update_in_db.php for final coding. Just comment this echo out. Now, we will proceed only if the form has been submitted so, create a conditional statement here again as we did many times before, just put $_POST in here. In the execution area, just grab all the values coming from the update form, i.e. name, username and password and store all of them in variables. Just echo all of these to verify, everything is working fine.
if(isset($_POST)){
echo $userID = $_POST['userID'];
echo $name = $_POST['name'];
echo $username = $_POST['username'];
echo $password = $_POST['password'];
}
So, we are getting all the values, it’s perfectly fine.Remove all the echo from here. Now it’s time to bring the update query here we wrote in the start of ‘update delete through PHP’ training session. So, cut it from here and paste it in here right below this code, but inside, if, condition. You can see this query is hard quoted, we need to make it dynamic. So, let’s just replace all the hard quoted values with the variables we are getting from $_POST array. Change this number with $userID, name with $name and keep it within single quotes, username with $username and password with $password. Now, this is our dynamic query now, will work with update functionality.
mysql_query("
UPDATE `users` SET `name` = '$name', `username` = '$username',
`password` = '$password'
WHERE `userID` = $userID
") or die(mysql_error());
Put this whole query in a variable as we did several times before, and you might have guessed what we need here. Just create another if statement, so that, if this query executes successfully, echo ‘User was updated successful having id’ and concatenate it with $userID. Otherwise, echo ‘User was not updated successfully’, append at the end, ‘Please try again.’
update_in_db.php Page
require_once '../day10/connection_with_db.php';
//echo 'Update the record finally.';
if(isset($_POST)){
$userID = $_POST['userID'];
$name = $_POST['name'];
$username = $_POST['username'];
$password = $_POST['password'];
$qr = mysql_query("
UPDATE `users` SET `name` = '$name', `username` = '$username',
`password` = '$password'
WHERE `userID` = $userID
") or die(mysql_error());
if($qr){
echo 'User was updated successfully having ID: '. $userID;
} else {
echo 'User was not updated having ID: '.$userID .'. Please try again.';
}
}
So, I hope everything is fine and we have created everything we need. Let’s run itthrough the browser. Go to the users listing page i.e. update_delete_users.php and refresh it. Now, click update to update any of the records, and rightly so, it sends us to the update_form.php and displays the related data of userID 5 within form fields. Now, let’s make a little change here by providing password and let’s click the update button. Here we go, the success message. So, finally we have updated the data of user having userID 5. Let’s verify it from the users’ table. Just refresh the table again and here you can see the data has been updated. Whenever you create any kind of functionality, just keep in mind that you should check each code you writefor several timesuntil and unless you are completely satisfied with the functionality. Let’s update userID 8 which has no data in it. Let’s put some dummy data here, fill all the fields, click update, and it’s updated successfully. Just refresh the user listing page and you can see data is showing against number 8. Let’s update userID 9 too, put some data and update and it’s been updated successfully too. We can verify through users table, as well as from our users listing page. You can update any record, let’s try one last time.And let’s update this record. Just put some dummy data for this too, hit update and it’s been updated successfully.
You should keep in mind that although we have learnt many things but this is just toput you on track. Now, the real game has begun. You have to learn lots of things ahead along with your experience. Whenever, you will work on a new project, a new door to new learning opportunities opens. This is totally up to you, do you avail the opportunity or not. Never hesitate to learn new things. This is also the era, when you have access to everything online from your computer screen. You can get help from internet anytime, there is solution to every problem you might have. So, just get in the mood of learning more things and do everything on your own. This will teach you more and you will never forget it again.
This is all for now. From tomorrow, we are going to start creating CRUD with Admin Panel and Login System. See you in day 14. Take Care.