Striving to know? How are these web developers making websites that we can’t imagine? Is there any rocket science to learn web development? Especially with an open source platform for PHP web development. A normal computer engineering student will definitely want to know the answer. Because everyone is not getting the practicality of coding structure of programming languages. We all know the language, but don’t know how to talk to them? Let us learn the language today.
Making PHP a Mother Tongue!
Every language has some simple functionalities to understand and if you go through the basics you can be the leader next day. PHP has a CRUD to understand.
Prerequisites: Guessing You have Downloaded the PHP, following installation of MySQL because all the operations we are going to perform on this database.
What Will We Learn Here? A Neat & Core Part of Your Engagement here:
Connecting PHP to DataBase(MySQL)
Creating Table / Inserting Records
Reading Database(Displaying on the website)
Updating Data(we change values into the table and it should be updated in the database)
Delete data from the front end and make it deleted in the backend
CRUD - Create, Read, Update, Delete
CRUD simply stands for creating data, making it available for reading, updating it whenever needed and deletion of the data.
Delving into the very first instance of making database and connecting to the PHP framework is possible with this coding snippet :
Connecting PHP to Database
Nothing is more beautiful and working than simplicity. Let us try it today.
Following is the code which You’ll write as in server-side scripting. We can call it a link between your language and the database. A connecting thread to your data and the language through which you are accessing it.
Write it into the SQL database to create the database.
CREATE DATABASE `db1`
CREATE TABLE `DB1`. `users`(
`user_id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`first_name` VARCHAR( 25 ) NOT NULL ,
`last_name` VARCHAR( 25 ) NOT NULL
) ENGINE = InnoDB;
Write following into the config.php file. Make one file under the project folder. Here the connection happens.
<?php
$host = "localhost";
$user = "root";
$password = "";
$database1 = "db1";
mysql_connect($host,$user,$password);
mysql_select_db($database1);
?>
You are done with the database created in the backend and connection is established. You have made your database ready to accept values, insertions or whatever you call it is ready to have operations.
Creating Table / Inserting Records
Note: We are focussing on PHP codes only and not the HTML designing. Put these codes right before your HTML design of a table.
Making PHP a Mother Tongue!
Every language has some simple functionalities to understand and if you go through the basics you can be the leader next day. PHP has a CRUD to understand.
Prerequisites: Guessing You have Downloaded the PHP, following installation of MySQL because all the operations we are going to perform on this database.
What Will We Learn Here? A Neat & Core Part of Your Engagement here:
Connecting PHP to DataBase(MySQL)
Creating Table / Inserting Records
Reading Database(Displaying on the website)
Updating Data(we change values into the table and it should be updated in the database)
Delete data from the front end and make it deleted in the backend
CRUD - Create, Read, Update, Delete
CRUD simply stands for creating data, making it available for reading, updating it whenever needed and deletion of the data.
Delving into the very first instance of making database and connecting to the PHP framework is possible with this coding snippet :
Connecting PHP to Database
Nothing is more beautiful and working than simplicity. Let us try it today.
Following is the code which You’ll write as in server-side scripting. We can call it a link between your language and the database. A connecting thread to your data and the language through which you are accessing it.
Write it into the SQL database to create the database.
CREATE DATABASE `db1`
CREATE TABLE `DB1`. `users`(
`user_id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`first_name` VARCHAR( 25 ) NOT NULL ,
`last_name` VARCHAR( 25 ) NOT NULL
) ENGINE = InnoDB;
Write following into the config.php file. Make one file under the project folder. Here the connection happens.
<?php
$host = "localhost";
$user = "root";
$password = "";
$database1 = "db1";
mysql_connect($host,$user,$password);
mysql_select_db($database1);
?>
You are done with the database created in the backend and connection is established. You have made your database ready to accept values, insertions or whatever you call it is ready to have operations.
Creating Table / Inserting Records
Note: We are focussing on PHP codes only and not the HTML designing. Put these codes right before your HTML design of a table.
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-save']))
{
// variables for input data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
// variables for input data
// sql query for inserting data into database
$sql_query="INSERT INTO users(first_name,last_name,user_city)
VALUES('$first_name','$last_name','$city_name')";
mysql_query($sql_query);
} ?>
Don’t forget to insert Design. Nowadays hire PHP developer tag is in demand And why should you miss it? Learn it from the basics.
Reading Database (Displaying on the website)
Code snippet for selecting the data from the specific table. Because we will not be having a single table in a database. And we have to select which data to be displayed on the screen.
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
We can write like this:
<?php
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
while($row = mysql_fetch_array($result))
{
?>
<!--Add HTML code here to display records--->
<?php
}
?>
Updating Data(we change values into the table and it should be updated in the database)
Here first we need to select those data which want it to be displayed on the page from the user's table. So let’s select the data.
if(isset($_GET['edit_id']))
{
$sql_query="SELECT * FROM users WHERE user_id=".$_GET['edit_id'];
$result_set=mysql_query($sql_query);
$fetched_row=mysql_fetch_array($result_set);
}
Following the appropriate selection of data, we need to make it update on the page:
if(isset($_POST['btn-update']))
{
// variables for input data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$city_name = $_POST['city_name'];
// variables for input data
// sql query for update data into database
$sql_query = "UPDATE users SET first_name='$first_name',last_name='$last_name',user_city='$city_name' WHERE user_id=".$_GET['edit_id'];
mysql_query($sql_query);
// sql query for update data into database
}
Delete data from the front end and make it deleted in the backend
Using the function of deletion program we can make any records to be deleted by clicking on it. We need to execute following code.
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM users WHERE user_id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: $_SERVER[PHP_SELF]");
}
Here we have taken all the php coding related to CRUD example. Rest is the designing part of the data/ form/table that we can perform using HTML. the main learning part of PHP development Company is using the right functions with appropriate PHP coding.
Conclusion
PHP is such an easy language to understand and make it executed for all sorts of web applications. It's an amazing open source language to learn, code and develops. The latest eCommerce technology Magento is based on this popular language.
Nowadays every business man want to get their own website where they can put details about their company, services, products and contact details. So, visit to ITSWS technologies and get effective business website at reasonable price. For details call us on 0120-4749624, +91-8459780634.
ReplyDeleteDynamic web designing in Lucknow
Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. hyip templates
ReplyDelete