PHP — Very Simple Way Insert to Database for Newbie
Some people, i mean newbie still very difficult to know how to insert database using PHP. As we know, PHP is basic program that very easy to use and very simple to connect with database. Check this out. ohh sorry, make sure you already serve this requirement.
Basic Requirement
- Install Xampp (for windows user)
- Install PHP
Let’s Practice
- Open Database, if you’re using MySQL on Xampp just open this link http://localhost/phpmyadmin. make sure you have start Apache and Mysql on Xampp
- Create new database, now i create try database.
3. Create new table, i give it name TX_BOOK and give field like this. then OK
Finnaly if you get view like below, you success create database and table absolutly.
4. Now, open your PHP project folder, just open xampp/htdoc/your_folder. create new file name index.php. code like this.
Then open in your browser, you will get view like this
5. Next, create connection to database, wait i will create it for you.
Just change as your configuration database, then you can check it like this. wait, mention on my url. you can check with adding file name on url.
If it success, mean you success create connection PHP and database. Then how to insert data to database. Simple, create new file inputProcess.php example and fill with this code. here the code and i will explain it.
wait, in that code i write fill with sql query. what it mean, follow my step. how to get sql query. first open your table in your database choose insert/tambahkan.
Fill like that, than save and you will get query like this.
Copy that query, than put on fill with sql query in inputProcess.php. Then change value parameter as input like this.
Finally, let’s test it
Running Test
I showing you that DB is Empty now, then let’s open your program
I fill data like that, and when i clik save,
Data Inserted to database Successfully.