Update values to MySQL Database using PHP

 Update values to MySQL Database using PHP


Database and Tables creation in phpMyAdmin

  • Start the server with database
  • Go to => localhost/phpmyadmin
  • Enter the username and password (you can fine default username and password in config.inc in phpMyAdmin folder)
  • create a database as follows,
Create Database
  • Now create the tables and add attributes as you want as follows,
Student Table
Course Table
Lecture Table

St_Co Table
  • Let's give the relationships now as, click database => More => Designer
  • You can see the tables which you created there
  • Click the "Create Relationship" from the menu.
Click on Create relationship
  • Now select Primary keys and Foreign keys correctly and you can see as follows after,
After giving relationships

That's all we have to do in phpMyAdmin for creation database and tables. If you face any problems while creating contact me on WhatsApp.


UI using HTML and CSS

Let's create some forms in HTML to submit where the inputs will be updated as values of tables.
Here is a sample code and output,

HTML and Output


  • Open form element has two attributes, action and method, where once the form get submitted the PHP file in action and POST or GET method will get executed.

Create PHP file to connect database and POST the Vaues

  • We create a PHP file same as value given to action attribute in form element.
  • Connect MySQL database using the "localhost, username, password, database, port(if required)". For more information click
  • Now let's write the query and assign to a variable when the database is connected.
  • And using mysqli_query() method, we can execute the query which we assigned to variable. For more information click
  • Look at the following code how I have written it,
PHP code

After this just give the values to the form as follows and click "Add",

Form filling

You can see the output displays as follows,

Output when click Add
Now the values you entered stored in the database. You can check the database, the table to which you update the values.

Database

Note: There various place where you can mistake. Once any error occur try to find and fix it. Here are few examples,
  • phpMyAdmin username or password would not be correct.
  • While giving relationship, first understand the relationship well and then give.
  • When creating form, you should give name attribute to each input to identify it from PHP NOT id attribute.
  • PHP codes error can be identified through the output itself.
This is just the basic connection between HTML and database. I will create step by step blog soon.

You can catch me through,

Thank You


Comments

Post a Comment

Popular posts from this blog

Search results in MySQL database using PHP

Introduction to React Native Navigation