Download Lecture-notes

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
ITX2000
Remote hosts and web servers
Week 6 – CW1
Prof. Xiaohong (Sharon) Gao
Room: T125
Ext: 12252
Email: [email protected]
Reference: http://www.w3schools.com/php
ITX2000 Course work: Course Work 1(50% marks)
Task
 Installing XAMPP software in a USB stick
 creating a personal web page to describe your birthplace,
 including photos to highlight the landmarks of this
 country/city/town/village
 This web page allows a feedback form, so that viewers can send their
comments no your webpage or to make recommendations
 , i.e., a guest book.
a. Use Apache HTTP server
 b. Use Mysql to provide the comments database
 c. Create a database/table to retain/save users’ comments.
 d. Use PHP language to realise client- server communication

Example -1:
Example -2
Step 1 – Start Apache
Step 2 – Start MySQL
Step 3 – create a table of guestbook
mysql> use test;
//select a database, e.g., ‘test’;
Step 4 – web interface with PHP
- Three PHP files are needed.
1. guestbook.php
2. add-guestbook.php
3. view-guestbook.php
Webpage – hometown.htm
<html>
<body>
<font color = 'RED'>
<h1> Introduction to My Home Town </h1>
</font>
<p> I was born in <a href='http://en.wikipedia.org/wiki/China'><b> China.</b> </a> </P>
<p> <a href='guestbook.php'> GuestBook (send your comments here.) </a> </p>
This is the China map.
<br>
<img src='mdx-logo.jpg'>
</body>
</html>
Step 5 – web interface of guestbook.php
<html>
<body>
<h1> My Hometown Guestbook </p>
<form action=“add-guestbook.php" method="post">
Name: <input type = "text" name="name"><br>
E-mail: <input type = "text" name="email"><br>
Comments: <input type = "text“ name="comments"><br>
<input type="submit">
</form>
</body>
</html>
Step 6 – Add-guestbook data to MySQL table
<?php
$host="localhost";
$username="root";
$password="";
$db_name="test";
$tbl_name="guestbook";
// Host name
// Mysql username
// Mysql password
// Database name
// Table name
mysql_connect ("$host", "$username", "$password“) or die ("cannot connect server ");
mysql_select_db ("$db_name") or die ("cannot select DB");
$name = $_POST["name"];
$email = $_POST["email"];
$comments = $_POST["comments"];
$sql="INSERT INTO guestbook VALUES ('$name', '$email', '$comments')";
$result=mysql_query($sql);
if($result){
echo "Successful“ . "<BR>";
echo "<a href='view-guest.php'>View guestbook</a>"; // link to view guestbook page
}
mysql_close();
?>
Step 6 – view-guestbook.php
<?php
$host= "localhost";
$user = "root";
$passwd = "";
$database = "test";
$tbl_name = "guestbook";
mysql_connect ($host, $user, $passwd) or die("cannot connect server ");
mysql_select_db( $database) or die("cannot select DB");
$result=mysql_query("SELECT * FROM $tbl_name");
while($rows = mysql_fetch_array($result)){
echo $rows['name'] . " “ .$rows['Email'] . " “ . $rows['comments'] . "<br>";
}
mysql_close();
//close databass
?>
Summary

Start working on course work 1.
Related documents