Friday, 7 August 2015

How to Insert Data in a Database Using PHP



INSERTING DATA IN DATABASE

Php is a server side scripting language it allows to store data into database at server level. In this post I will illustrate you how insert data with Sql insert query in PHP.
First of all, I have created  HTML form, in which method is set to post ,to hide values in URL which flows on form submission.
Next, I wrote PHP code where the main functionality of insertion of values into database is performed.
At MySql database I have created a database named “colleges” and table named “students” which consists of five fields viz. “student_id”, “student_name”, “student_email”, “student_contact”, “student_address”.

CREATE DATABASE IF NOT EXISTS colleges;
CREATE TABLE students(
student_name varchar(255) NOT NULL,
student_email varchar(255) NOT NULL,
student_contact varchar(255) NOT NULL,
student_address varchar(255) NOT NULL
)

HTML File – insert.php
1.       Consists of form div “form”.
<!DOCTYPE html>
<html>
<head>
<title>PHP insertion</title>
<link href="css/insert.css" rel="stylesheet">
</head>
<body>
<div class="maindiv">
<!--HTML Form -->
<div class="form_div">
<div class="title">
<h2>Insert Data In Database Using PHP.</h2>
</div>
<form action="insert.php" method="post">
<!-- Method can be set as POST for hiding values in URL-->
<h2>Form</h2>
<label>Name:</label>
<input class="input" name="name" type="text" value="">
<label>Email:</label>
<input class="input" name="email" type="text" value="">
<label>Contact:</label>
<input class="input" name="contact" type="text" value="">
<label>Address:</label>
<textarea cols="25" name="address" rows="5"></textarea><br>
<input class="submit" name="submit" type="submit" value="Insert">     </form></div></div>
</body>
</html>

PHP Code segment

2.       Insert form information into database.
<?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("colleges", $connection); // Selecting Database from Server
if(isset($_POST['submit'])){ // Fetching variables of the form which travels in URL
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$address = $_POST['address'];
if($name !=''||$email !=''){
//Insert Query of SQL
$query = mysql_query("insert into students(student_name, student_email, student_contact, student_address) values ('$name', '$email', '$contact', '$address')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysql_close($connection); // Closing Connection with Server
?>

Css File – insert.css
3.       Includes basic styling of  HTML elements.

@import "http://fonts.googleapis.com/css?family=Droid+Serif";
/* The Above Line Is To Import Google Font Style */
.maindiv {
margin:30px auto;
width:980px;
height:500px;
background:#fff;
padding-top:20px;
font-family:'Droid Serif',serif;
font-size:14px
}
.title {
width:500px;
height:70px;
text-shadow:2px 2px 2px #cfcfcf;
font-size:16px;
text-align:center
}
.form_div {
width:70%;
float:left
}
form {
width:300px;
border:1px dashed #aaa;
padding:10px 30px 40px;
margin-left:70px;
background-color:#f0f8ff
}
form h2 {
text-align:center;
text-shadow:2px 2px 2px #cfcfcf
}
textarea {
width:100%;
height:60px;
border-radius:1px;
box-shadow:0 0 1px 2px #123456;
margin-top:10px;
padding:7px;
border:none
}
.input {
width:100%;
height:30px;
border-radius:2px;
box-shadow:0 0 1px 2px #123456;
margin-top:10px;
padding:7px;
border:none;
margin-bottom:20px
}
.submit {
color:#fff;
border-radius:3px;
background:#1F8DD6;
padding:5px;
margin-top:40px;
border:none;
width:100%;
height:30px;
box-shadow:0 0 1px 2px #123456;
font-size:18px
}
p {
color:red;
text-align:center
}
span {
text-align:center;
color:green
}

Wednesday, 5 August 2015

INFORMATION SYSTEMS EXAM KASNEB MAY 2013



KASNEB ICTT LEVEL II

INFORMATION SYSTEMS

THURSDAY: 30 May 2013.                                                                                                                    Time Allowed: 3 hours.

Answer any FIVE questions.                                                                                                                   ALL questions carry equal marks.

QUESTION ONE
(a)           Briefly explain the following information systems:
(i)            Expert system.                                                                            (2 marks)

(ii)           Decision support system.                                                              (2 marks)

(iii)          Transaction processing system.                                                                                                        (2 marks)

(b)           "An organisation is considered to be a system"
Justify the above statement.                                                                      (10 marks)

(c)            Identify the functions of the output component in a computer system.                                                         (4 marks)
(Total: 20 marks)

QUESTION TWO
(a)           Appraise four advantages of outsourcing software.                                                                               (8 marks)

(b)           Evaluate three system changeover strategies giving an advantage and a disadvantage of each.                         (12 marks)
(Total: 20 marks)

QU ES HON THREE
(a)            Highlight four components of each of the following aspects of an information system:
(i)            Technological.                                                                                         (4 marks)

(ii)           Organisational.                                                                                         (4 marks)
(b)           Outline four methods commonly used in data collection.                                                                               (8 marks)

(c)           Differentiate between "systems security" and "data security".                                                                      (4 marks)
(Total: 20 marks)

QUESTION FO R
(a)            Systems analysts develop data flow diagrams (DFDs) as part of a system's development.

Reqnired:
(i)            Explain the meaning of DFDs.                                                                                                         (2 marks)

(ii)           Using illustrations, label four types of diagrams used in data flow diagramming system's technique. (4 marks)
(b)           List six data validation checks.                                                                                                        (6 marks)

(c)            (i)            Define the term "coding   relation to system design.                                                                         (2 marks)
(ii)           Highlight six characteristics of a good program code.                                                                        (6 marks)
(Total: 20 marks)


QUESTION FIVE
(a)            Regardless of the kind of data processed or kind of equipment or device used, all data processing systems involve at
least three basic steps.

Required:
Summarise the three basic steps of data processing.                                                                                      (6 marks)
(b)           Describe five basic components of a decision support system (DSS).                                                          (10 marks)

(c)           Outline four qualities of good information.                                                                                                    (4 marks)
                                                                                                                                                                                     (Total: 20 marks)

QUESTION SIX
(a)            Highlight four reasons why one would either hire or lease computers and related equipment.                        (4 marks)

(b)           Outline six types of errors that could occur during data entry.                                                                         (6 marks)
(c)            Explain four characteristics of an executive information system (EIS).                                                           (4 marks)

(d)           Illustrate the operational section of an information technology (IT) department of a medium size organisation showing at
least six operators.                                                                                        (6 marks)
(Total: 20 marks)

QUESTION SEVEN
(a)            Each stage of systems development ends with a tangible product.

With reference to the above statement, state the products of the following stages:
(i)             Problem definition.                                                                     (1 mark)

(ii)           Feasibility study.                                                                                                                           (1 mark)

(iii)          System design.                                                                                                                               (I mark)

(iv)          System analysis.                                                                                                                          (1 mark)
(b)            Identify four contents of the product of each of the stages in (a) above.                                                     (16 marks)
(Total: 20 marks)












Propellerads