aung zay ya dw assignment (done)

40
Aung Zay Ya 8th August 2014

Upload: aung-zay-ya

Post on 13-Apr-2017

53 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Aung Zay Ya DW Assignment (Done)

Aung Zay Ya

8th August 2014

Page 2: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

NCC Education

Level 5 Diploma in Computing

Dynamic Website

Centre Name : MCC, Yangon

Assignment Title : Information Gathering Tool

Exam Cycle : August 2014

Candidate Name : Aung Zay Ya

NCC Education ID No . : 00155002

Submission Date : 8.8.2014

:

Marker’s Comment :

Moderator’s Comment :

Mark: Moderated Mark : Final Mark :

a u n g z a y y a P a g e 1 | 36

Page 3: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Statement and Confirmation of Own Work

Each time you submit an assignment you must attach this statement as the cover page for both the hard copy and the electronic version. If the statement is missing your work will not be marked.

Student Declaration

I have read and understood NCC Education’s Policy on Academic Dishonesty and Plagiarism.

I can confirm the following details:

Programme/Qualification Name: Level 5 Diploma in ComputingStudent ID/Registration number:

00155002Name: Aung Zay YaCentre Name: MCC, YangonModule Name: Dynamic WebsitesModule Leader: Daw Htike Wai Kyaw

Number of words:

I confirm that this is my own work and that I have not plagiarized any part of it. I have also noted the assessment criteria and pass mark for assignments.

Due Date:

Student Signature:

Submitted Date:

a u n g z a y y a P a g e 2 | 36

Page 4: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

ContentsAcknowledgement.........................................................................................................................6

Introduction....................................................................................................................................7

Task 1..........................................................................................................................................10

Create a setup page for the database.......................................................................................8

Data Design...............................................................................................................................8

Create a database and connect.................................................................................................9

User Table Create..................................................................................................................9

Question Table Create.........................................................................................................10

Questionoption Table Create..............................................................................................11

Questioncategory Table Create...........................................................................................12

Answer Table Create............................................................................................................12

Task 2..........................................................................................................................................13

Creating the login and registration...........................................................................................13

dw_assignment_registration.php..........................................................................................18

Error Alerts and Successful Registration..............................................................................21

LogIn System...........................................................................................................................25

dw_assignment_login.php....................................................................................................25

dw_assignment_login_again.php.........................................................................................27

Error Alerts and Successful LogIn........................................................................................29

Task 3..........................................................................................................................................16

login.php...............................................................................................................................16

insert_signup.php.................................................................................................................16

Welcome.php........................................................................................................................16

Mobile.php............................................................................................................................16

Laptop.php............................................................................................................................16

Camera.php..........................................................................................................................16

Task 4..........................................................................................................................................17

mobile question displayed....................................................................................................17

laptop question displayed........................................................................................................18a u n g z a y y a P a g e 3 | 36

Page 5: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

camera question displayed................................................................................................19

Task 5.........................................................................................................................................19

Insert Mobile, Laptop, Camera Data........................................................................................19

Task 6..........................................................................................................................................20

Use of sessions and cookies...................................................................................................20

References..................................................................................................................................21

a u n g z a y y a P a g e 4 | 36

Page 6: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Acknowledgement

I would like to express my special thanks of gratitude to my class tutor Daw Phyo Thwe Aye as

well as my lecturer Daw Htike Wai Kyaw who gave me the golden opportunity to do this

assignment – Information Gathering Tool, which also helped me in doing a lot of Research and I

came to know about so many new things I am really thankful to them. Secondly, I would also

like to thank my parents and friends who helped me a lot in finalizing this assignment within the

limited time frame.

a u n g z a y y a P a g e 5 | 36

Page 7: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

IntroductionI am Aung Zay Ya from Myanmar. I am majoring in Business Information and Technology (BIT)

Level 5 Diploma in Computing and now studying at MCC Training Institute, Yangon Campus.

a u n g z a y y a P a g e 6 | 36

Page 8: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Task 1

Create a setup page for the database

Data Design

In the database “gatherinformation”, there are six

tables with their corresponding fields and they are shown below.

Table Names Attribute Names

Users UID

Name

Gender

Email

Password

PhoneNo

Address

Questions QuestID

Quest_Name

Quest_CateID

Quest_Type

Questionoption Question_option_ID

Question_option_Name

Question_ID

Questioncategory QcID

Name

Answer AnswerID

UserID

QuestionID

Answer

a u n g z a y y a P a g e 7 | 36

Page 9: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

The PHP file is opened with Google Chrome browser and other files will be opened with that

browser too. Since there is no table in the database, two tables will need to be added.

Task 1

Create a setup page for the database

$query="CREATE DATABASE gatherInformation";

$ret=mysql_query($query,$connection);

User Table Create

CREATE TABLE IF NOT EXISTS `users` (

`UID` int(4) NOT NULL AUTO_INCREMENT,

`Name` varchar(50) NOT NULL,

a u n g z a y y a P a g e 8 | 36

Question_Category Question Question_Option

AnswerUser

Page 10: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

`Gender` varchar(255) NOT NULL,

`Email` varchar(50) NOT NULL,

`Password` varchar(50) NOT NULL,

`PhoneNo` varchar(50) DEFAULT NULL,

`Address` varchar(50) DEFAULT NULL,

PRIMARY KEY (`UID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=32 ;

Questions table create

CREATE TABLE IF NOT EXISTS `questions` (

`QuestID` int(11) NOT NULL AUTO_INCREMENT,

`Quest_Name` text NOT NULL,

`Quest_CateID` int(11) NOT NULL,

`Quest_Type` int(11) NOT NULL COMMENT '1 = Multiple Choicek, 2 = Text, 3 = Number',

PRIMARY KEY (`QuestID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;

a u n g z a y y a P a g e 9 | 36

Page 11: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Questionoption table create

CREATE TABLE IF NOT EXISTS `questionoption` (

`question_option_ID` int(11) NOT NULL AUTO_INCREMENT,

`question_option_name` varchar(255) NOT NULL,

`question_ID` int(11) NOT NULL,

PRIMARY KEY (`question_option_ID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;

Questioncategorya u n g z a y y a P a g e 10 | 36

Page 12: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

CREATE TABLE IF NOT EXISTS `questioncategory` (

`QcID` int(11) NOT NULL AUTO_INCREMENT,

`Name` varchar(255) NOT NULL,

PRIMARY KEY (`QcID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

Answer table create

CREATE TABLE IF NOT EXISTS `answer` (

`AnswerID` int(11) NOT NULL AUTO_INCREMENT,

`UserID` int(11) NOT NULL,

`QuestionID` int(11) NOT NULL,

`answer` text NOT NULL,

PRIMARY KEY (`AnswerID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=152 ;

a u n g z a y y a P a g e 11 | 36

Page 13: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Task 2

Create the login and registration

a u n g z a y y a P a g e 12 | 36

Page 14: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

That’s login form create PHP, CSS, Javascript and HTML. Login verification consists of these form. It can’t enter fake email and fake password . Type miss the following message box appear.

a u n g z a y y a P a g e 13 | 36

Page 15: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

If user has been registered user can the login to INFOGATE Home page. If user has not been registered. User can the click sign up.

a u n g z a y y a P a g e 14 | 36

Page 16: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

And the rise the user register page. User register with own email and own password.

For registration account create name must be require. Type the valid name. Sign Up button click with the name input box is one character . The message box is appear.

a u n g z a y y a P a g e 15 | 36

Page 17: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

For registration account create email must be require. Type the valid email. Sign Up button click with the email input box is not valid. The message box is appear.

a u n g z a y y a P a g e 16 | 36

Page 18: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

For registration account create password must have 6 character require. Type the valid password. Sign Up button click with the password input box is not valid. The message box is appear.

a u n g z a y y a P a g e 17 | 36

Page 19: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Can’t duplicate username & email.

a u n g z a y y a P a g e 18 | 36

Page 20: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

a u n g z a y y a P a g e 19 | 36

Page 21: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

a u n g z a y y a P a g e 20 | 36

Page 22: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

If this three input box is valid. You can create account successful.

Added New User

a u n g z a y y a P a g e 21 | 36

Page 23: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

a u n g z a y y a P a g e 22 | 36

Page 24: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Task 3

Mobile.php, Laptop.php, Camera.php

It code is select the old answer from database and decide 1 = radio, 2 = text, 3 = textarea. User can see and answer corrective answer from page.

$sel_ans_qry = "SELECT * FROM answer WHERE UserID = '$user_id' AND questionID = '$question_id' ";

$anser_sro = mysqli_query($con,$sel_ans_qry);

$anser_arr = mysqli_fetch_assoc($anser_sro);

$answer = $anser_arr['answer'];

echo "<li><p>$question_name</p></li>";

a u n g z a y y a P a g e 23 | 36

Page 25: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

if ($question_type == 1)

{

$option_result = mysqli_query($con,"SELECT * from `questionoption` WHERE `question_ID` = $question_id");

//$option_result = mysqli_query($con,"SELECT * FROM `questionoption` GROUP BY `question_ID` HAVING `question_ID` = $question_id");

$option_count = mysqli_num_rows($option_result);

for($j=0;$j<$option_count;$j++)

{

$options_row = mysqli_fetch_assoc($option_result);

$option_name = $options_row['question_option_name'];

$option_id = $options_row['question_option_ID'];

if ( $answer == $option_id )

$checked = 'checked';

else

$checked = '';

echo "<label class='btn btn-default'><input type='radio' value ='$option_id' name='question$question_id' $checked/>&nbsp;&nbsp;&nbsp;$option_name&nbsp;&nbsp;&nbsp;</label>";

}

$tmpStr = $question_name;

}else if ($question_type == 2 ){

echo "<textarea id='' name='question$question_id' rows='10' cols='60'>$answer</textarea>";

}else{

echo "<div class='input-group'><input type='text' name='question$question_id' value='$answer' style='width:50px;' /></div>";

}

a u n g z a y y a P a g e 24 | 36

Page 26: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Task 4

User can choose the desire question in this page.

a u n g z a y y a P a g e 25 | 36

Page 27: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

If user click the “mobile” button. User see the question of mobile in following pic.

If user click the “laptop” button. User see the question of mobile in following pic.

a u n g z a y y a P a g e 26 | 36

Page 28: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

If user click the “camera” button. User see the question of mobile in following pic.

These all pages mobile.php, laptop.php, camera.php use the following code.

$CatID = $_GET['ID'];

if(isset($_POST['btnsave']))

{

$del_qry = "DELETE FROM answer WHERE UserID = '$user_id' AND questionID IN (SELECT QuestID FROM questions WHERE Quest_CateID = '$CatID' ) ";

mysqli_query($con,$del_qry);

foreach( $_POST as $k=>$v )

{

if(substr($k, 0, 8) == 'question' )

{

$question_id = substr($k, 8);

$query="INSERT INTO answer(userID, questionID,answer) VALUES ($user_id,$question_id, '$v')";

mysqli_query($con,$query);

question=$question_id answer=$v<br>";}

}

unset($_POST);

}

a u n g z a y y a P a g e 27 | 36

Page 29: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

$query = mysqli_query($con,"SELECT * from questions q LEFT JOIN questionoption qp ON q.QuestID = qp.question_ID WHERE Quest_CateID = $CatID ORDER BY q.QuestID" );

$result= mysqli_num_rows($query);

//echo $result;

$qname = "";

echo "<form name='frmsave' id='frmsave' method='post'>";

echo "<table><tr><td align='left'>";

echo "<ol>";

for($i=0;$i<$result;$i++)

{

$row = mysqli_fetch_assoc($query);

$question_name = $row['Quest_Name'];

$question_type = $row['Quest_Type'];

$question_id = $row['QuestID'];

$answer = $row['answer'];

if($qname!=$question_name)

{

$qname = $question_name;

$sel_ans_qry = "SELECT * FROM answer WHERE UserID = '$user_id' AND questionID = '$question_id' ";

$anser_sro = mysqli_query($con,$sel_ans_qry);

$anser_arr = mysqli_fetch_assoc($anser_sro);

$answer = $anser_arr['answer'];

echo "<li><p>$question_name</p></li>";

if ($question_type == 1)

{

$option_result = mysqli_query($con,"SELECT * from `questionoption` WHERE `question_ID` = $question_id");

//$option_result = mysqli_query($con,"SELECT * FROM `questionoption` GROUP BY `question_ID` HAVING `question_ID` = $question_id");

$option_count = mysqli_num_rows($option_result);

a u n g z a y y a P a g e 28 | 36

Page 30: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

for($j=0;$j<$option_count;$j++)

{

$options_row = mysqli_fetch_assoc($option_result);

$option_name = $options_row['question_option_name'];

$option_id = $options_row['question_option_ID'];

if ( $answer == $option_id )

$checked = 'checked';

else

$checked = '';

echo "<label class='btn btn-default'><input type='radio' value ='$option_id' name='question$question_id' $checked/>&nbsp;&nbsp;&nbsp;$option_name&nbsp;&nbsp;&nbsp;</label>";

}

$tmpStr = $question_name;

}else if ($question_type == 2 ){

echo "<textarea id='' name='question$question_id' rows='10' cols='60'>$answer</textarea>";

}else{

echo "<div class='input-group'><input type='text' name='question$question_id' value='$answer' style='width:50px;' /></div>";

}

}

}

Task 5

a u n g z a y y a P a g e 29 | 36

Page 31: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

User fill the new Survey.

And then user click the “Sign Out” button in these page.

a u n g z a y y a P a g e 30 | 36

Page 32: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

User again Log in with existing account.

Click the mobile button

a u n g z a y y a P a g e 31 | 36

Page 33: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

Now user can see existing answer in this page

User can be update in this page. See the following pic

a u n g z a y y a P a g e 32 | 36

Page 34: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

And then click the “Save” button. It’s changes In database. See in following pic

if(isset($_POST['btnsave']))

{

$del_qry = "DELETE FROM answer WHERE UserID = '$user_id' AND questionID IN (SELECT QuestID FROM questions WHERE Quest_CateID = '$CatID' ) ";

mysqli_query($con,$del_qry);

//print_r($_POST);echo '<br>';

a u n g z a y y a P a g e 33 | 36

Page 35: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

foreach( $_POST as $k=>$v )

{

if(substr($k, 0, 8) == 'question' )

{

$question_id = substr($k, 8);

$query="INSERT INTO answer(userID, questionID,answer) VALUES ($user_id,$question_id, '$v')";

mysqli_query($con,$query);

answer=$v<br>";

}

}

unset($_POST);

}

Task 6

Fulfill the same act, but most of the information does not get stored on a user’s computer is Session. It is available only as long as their browser is open and the session is active. Session using to get the user login ID.

Little files stored on a user’s computer that contain certain pieces of information are called Cookie.

They are then read in buy a web page can be available between pages.

Cookie is using to get the name.

<?php

session_start();

$user_id=$_SESSION['sess_usrLogin_id'];

$del_qry = "DELETE FROM answer WHERE UserID = '$user_id' AND questionID IN (SELECT QuestID FROM questions WHERE Quest_CateID = '$CatID' ) ";

mysqli_query($con,$del_qry);

?>

a u n g z a y y a P a g e 34 | 36

Page 36: Aung Zay Ya DW Assignment (Done)

Information Gathering Tool Dynamic Websites

References Dynamic Websites textbook

Designing and Developing a Website textbook

a u n g z a y y a P a g e 35 | 36