Insert Data & Fetch Data

Posted on

ddsgInsert Data & Fetch Data

Insert data and fetch data from database…

To create a form to insert the values in database we need 3 things


Php (or any midway language like java etc)

Mysqli ( database ,tables )

To start insert the alue into the database first we create the form in html language with help of notepad++. And save the file in www folder with new website folder page we include form and form tags like text field, combobox, buttons, textarea, radio buttons etc.

Example of job description (Here I show the code of html)

<form enctype=”multipart/form-data” action=”<? php echo $_SERVER[‘ PHP_SELF ‘];? >”method=”post” >

< div id=”form” >

<table ><h3 >job description</ h3 >

<tr ><td >Logo:< input type=”file” name=”log_o”/ ></ td ></tr >

<tr >< td >

<label for=”title” >job posting title</label >

<input type=”text” name=”title” >

</td ></tr >

<tr ><td >

<label for=”vancanies” >number of vancancies</label >

<input type=”text” name=”vancancies” >

</td ></tr >

<tr ><td >

<label for=”location” >work loc_ation</label >

<textarea name=”worklocation” ></textarea >

</td ></tr >

<tr ><td >

<label for=”city” >city</label >

<input type=”text” name=”city” >

</td ></tr >

<tr ><td >

<label for=”description” >job description</label >

<textarea name=”description” ></textarea >

</td ></tr >

<tr ><td >

<label for=”requirements.” >..requir_ements.</label >

<textarea name=”require” ></textarea >

</td ></tr >

<tr ><td >

<label for=”minimum” >minimum experience</label >

<select name=”experience” >

<option value=”10 years” >more than ten years</option >

<option value=”internship” >internship</option >

<option value=”without experience” >without experience</option >

<option value=”1 year” >one year</option >

<option value=”between 3-5 years” >between 3-5 year</option ></select >

</td ></tr >

<tr ><td >

<label for=”minimum std” >minimum studies</label >

<select name=”studies” >

<option value=”BA” >BA</option >

<option value=”LLBf” >LLB</option >

<option value=”BCA” >BCA</option >

<option value=”B.COM” >B.COM</option >

<option value=”BTECH” >BTECH</option >

<option value=”BHM” >BHM</option >

<option value=”BBA” >BBA</option ></select >

</td ></tr >

<h3 >contract details</h3 >

<tr ><td >

<label for=”position” >position type</label >

<select name=”position” >

<option value=”permanent” >permanent</option >

<option value=”internship” >internship</option >

<option value=”temporary” >temporary</option >

<option value=”for project” >for project</option >

<option value=”other” >other</option ></select >

</td ></tr >

<tr ><td >

<label for=”contact” >contact</label >

<input type=”text” name=”contact” >

<label for=”duration” >duration</label >

<select name=”shift” >

<option value=”fulltime” >fulltime</option >

<option value=”parttime-morning” >parttime-morning</option >

<option value=”parttime-evening” >parttime-evening</option ></select >

</td ></tr >

<tr ><td >

EXP Date:

<input type=”date” name=”date_exp” >

</td ></tr >

<tr ><td >

<label for=”salary” >salary</label >

<input type=”text” name=”salary” >

</td ></tr >

<tr ><td >

<input type=”submit” name=”ok” value=”submit” >

</td ></tr >

</table >

</div >

</form >

Here is the html code now put the php code

<? php

if(isset($_POST[‘ ok ‘]))


$exp_date=$_POST[‘ date_exp ‘];


//echo $exp_date;

$title=$_POST[‘ title ‘];

$img=$_FILES[‘ logo ‘][‘ name ‘];

//echo $img;

if(!move_uploaded_file($_FILES[‘ logo ‘][‘ tmp_name ‘],”upload_logo/”.$_FILES[‘ logo ‘][‘ name ‘]))


echo “error in upload”;


$van=$_POST[‘ vancancies ‘];

$worklocation=$_POST[‘ worklocation ‘];

$city=$_POST[‘ city ‘];

$des=$_POST[‘ description ‘];

$require=$_POST[‘ require ‘];

$exp=$_POST[‘ experience ‘];

$std=$_POST[‘ studies ‘];

$position=$_POST[‘ position ‘];

$contact=$_POST[‘ contact ‘];

$shift=$_POST[‘ shift ‘];

$salary=$_POST[‘ salary ‘];


$a=mysqli_query($con,”insert into jobs(`date_exp`,`posting_date`,`image`, `title`, `vancancies`,

`location`, `city`, `description`, `require`, `experience`, `studies`, `position_type`, `contact`, `shift`,






? >

It will insert the value into the table which we create in database we can check it from the phpmyadmin page with the help of localhost page and click on phpmyadmin link then database and table name.

How to retrieve the value from the database example??

To retrieve the value from the data base we have to create a connection with the database with the help of php code and html to show the value and database to store the value open the notepad++ write the html basic code .

<html >

<head >

<title >Fetch Data from table</title >

</head >

<body >

</body >

</html >

In body we start write the code of php which starts with <? Php and ends with ? >.

Now the first step is to create a connection between the database and php code $con=mysqli_connect(“localhost”,”root”,””,”job_portal”);

It create a connection with the database

Now the second step is to create query about what we want to fetch the data from the database $query=mysqli_query($con,”select * from jobs”);

Here we select the whole value from the database table name jobsNow the next step is to fetch the data from the query



It will fetch the data from the database

Next step is how to show the data

Echo $row[‘ column_name ‘];



{? >

<div id=”job_div” >

<div id=”frst” >

<div id=”image_div” >

<div id=”img_logo” >

<img src=”upload_logo/<? php echo $row[‘ image ‘];? >” height=”50px” width=”50px”/ >

</div >

<span ><img src=”webpic/cmpny.jpg” width=”10px” height=”10px” ><? php echo $row[‘ title ‘];?></span >

<span ><img src=”webpic/lo.png” width=”10px” height=”10px” ><? php echo $row[‘ location ‘];?></span >

<span ><img src=”webpic/lo.png” width=”10px” height=”10px” ><? php echo $row[‘ city ‘];? ></span >

</div >

<div id=”descript” >

<? php echo $row[‘ description ‘];? >

<? php echo $row[‘ date_exp ‘];? >

</div >

</div >

<? php echo $row[‘ require ‘];? >

<? php echo $row[‘ experience ‘];? >

<? php echo $row[‘ studies ‘];? >

<? php echo $row[‘ position_type ‘];? >

<? php echo $row[‘ contact ‘];? >

<? php echo $row[‘ shift ‘];? >

<? php echo $row[‘ salary ‘];? >

</div >

<? php }

Now the last step is close the connection which we create to fetch the data mysqli_close($con);

? >

With that easy method we can easily fetch the data from the database. we can also set the limit with the help of limit into the query like

Select * from table_name limit 5

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666


Please fill the FORM and we shall contact you soon.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s