Topic 9 Homework Marking Guide

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Course Name: Advanced Web Based Application Development

Topic: Retrieving and Displaying Data from a MySQL Database


Instructor: Dr. Obuhuma James
Activity: Homework Marking Guide

In refence to the homework for Topic 8, consider the following task.

Task:

Write a php code that displays the data captured in the database on a browser in a tabular
form. [10 Marks]
The code for the form and its validation should be as follows:

<?php

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

$result = mysql_query("SELECT * FROM datatable", $con);

echo "<table border = 1 >";

echo "<tr>\n<th align=left>";


echo("Name");
echo "</th>";

echo "<th align=left>";


echo("Email Address");
echo "</th>";

echo "<th align=left>";


echo("Gender");
echo "</th>";

echo "<th align=left>";


echo("Subject");
echo "</th>";

echo "<th align=left>";


echo("Suggestion");
echo "</th>";
echo "</tr>";

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))


{
echo "<td>";
echo($row["Name"] . " ");
echo "</td>";

echo "<td>";
echo($row["Email"] . " ");
echo "</td>";

echo "<td>";
echo($row["Gender"] . " ");
echo "</td>";

echo "<td>";
echo($row["Subject"] . " ");
echo "</td>";

echo "<td>";
echo($row["Suggestion"] . " ");
echo "</td>";

echo "</tr>";
}

echo "</table>";

mysql_close ($con);
?>

You might also like