0% found this document useful (0 votes)
24 views3 pages

Topic 8 Homework Marking Guide

The document provides instructions for developing a suggestion form using HTML and JavaScript for validation. It also provides instructions for processing submitted form data and inserting it into a MySQL database table. The form is to include fields for name, email, subject, and suggestion. JavaScript is used to validate that all fields are filled out before submission. Upon submission, PHP code is then used to connect to a MySQL database called 'suggestion' and insert the form data into a table.

Uploaded by

wannabedaniel77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Topic 8 Homework Marking Guide

The document provides instructions for developing a suggestion form using HTML and JavaScript for validation. It also provides instructions for processing submitted form data and inserting it into a MySQL database table. The form is to include fields for name, email, subject, and suggestion. JavaScript is used to validate that all fields are filled out before submission. Upon submission, PHP code is then used to connect to a MySQL database called 'suggestion' and insert the form data into a table.

Uploaded by

wannabedaniel77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Course Name: Advanced Web Based Application Development

Topic: Inserting and Manipulating Data in a MySQL Database


Instructor: Dr. Obuhuma James
Activity: Homework Marking Guide

Consider the following simple Suggestion Form.

Task:

a) Develop the form using HTML5. Include JavaScript for validation of form fields such that no
field is left empty upon submission. [10 Marks]

The code for the form and its validation should be as follows:

<!DOCTYPE html>
<html>
<head>
<title>Suggestion Form</title>

<script type=”text/javascript”>
function validateForm()
{
var name=document.forms["myForm"]["name"].value;
if (name==null || name=="")
{
alert("Name must be filled");
return false;
}

var email=document.forms["myForm"]["email"].value;
if (email==null || email=="")
{
alert("Email Address must be filled");
return false;
}

var subject=document.forms["myForm"]["subject"].value;
if (subject==null || subject=="")
{
alert("Subject must be filled");
return false;
}

var msg=document.forms["myForm"]["suggestion"].value;
if (msg==null || msg=="")
{
alert("Suggestion must be filled");
return false;
}

}
</script>

</head>
<body>

<p><b>Suggestion Form</b></p>

<form method="post" name="myForm" action="" onSubmit(validateForm();)>

<p>Name: <input type="text" name=”name”></p>


<p>Email Address: <input type="text" name=”email”></p>

<p>Subject: <input type="text" name="subject"></p>

<textarea rows="5" cols="40" name="suggestion">Type your suggestion here!!</textarea>


<br>
<br>
<input type="Submit" name="Submit" value="Susbmit">
<input type="Reset" name="Reset" value="Refresh">

</form>

</body>
</html>
b) On Submission, the Suggestion Form data is saved in a MySQL database called “suggestion”.
Create a database and table with appropriate fields that will store the data. Then,
implement the script that process form data and sends it to the database. [10 Marks]

The code for the script that processed form data should be as follows:

<?php
$server=”localhost”;
$user="root";
$password="";
$database="suggestion";
$con = mysql_connect($server,$user,$password);
@mysql_select_db($database, $con) or die( " Could not establish the connection!");

$name=$_POST['name'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$subject=$_POST['subject'];
$suggestion=$_POST['suggestion'];

$result = mysql_query("INSERT INTO datatable (Name, Email, Gender, Subject, Suggestion) VALUES
('$name','$email','$gender','$subject','$suggestion')", $link);

mysql_close ($con);
?>

You might also like