Name:

welcome.php The form data An OS is a program that controls the execution of application programs and acts as an interface between applications and the computer hardware. It can be thought of as having three objectives: • Convenience: An OS makes a computer more convenient to use. • Efficiency: An OS allows the computer system resources to be used in an efficient manner. • Ability to evolve: An OS should be constructed in such a way as to permit the effective development, testing, and introduction of new system functions without interfering with service."> Name:

welcome.php The form data An OS is a program that controls the execution of application programs and acts as an interface between applications and the computer hardware. It can be thought of as having three objectives: • Convenience: An OS makes a computer more convenient to use. • Efficiency: An OS allows the computer system resources to be used in an efficient manner. • Ability to evolve: An OS should be constructed in such a way as to permit the effective development, testing, and introduction of new system functions without interfering with service.">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Remote hosts and web servers

Similar presentations


Presentation on theme: "Remote hosts and web servers"— Presentation transcript:

1 Remote hosts and web servers
ITX2000 Remote hosts and web servers Week 5 – PHP – forms Prof. Xiaohong (Sharon) Gao Room: T125 Ext: 12252 Reference:

2 PHP – FORM handling A simple HTML form
Submit A simple HTML form <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> <input type="text" name=" "><br> <input type="submit"> </form> </body> </html> welcome.php The form data An OS is a program that controls the execution of application programs and acts as an interface between applications and the computer hardware. It can be thought of as having three objectives: • Convenience: An OS makes a computer more convenient to use. • Efficiency: An OS allows the computer system resources to be used in an efficient manner. • Ability to evolve: An OS should be constructed in such a way as to permit the effective development, testing, and introduction of new system functions without interfering with service.

3 PHP – FORM handling -- 2 Submit welcome.php
The form data is sent with the HTTP POST method. An OS is a program that controls the execution of application programs and acts as an interface between applications and the computer hardware. It can be thought of as having three objectives: • Convenience: An OS makes a computer more convenient to use. • Efficiency: An OS allows the computer system resources to be used in an efficient manner. • Ability to evolve: An OS should be constructed in such a way as to permit the effective development, testing, and introduction of new system functions without interfering with service.

4 PHP – FORM handling -- 3 // welcome.php – echo all the variables
<html> <body> Welcome <?php echo $_POST["name"]; ?> <br> Your address is: <?php echo $_POST[" "]; ?> </body> </html> An OS is a program that controls the execution of application programs and acts as an interface between applications and the computer hardware. It can be thought of as having three objectives: • Convenience: An OS makes a computer more convenient to use. • Efficiency: An OS allows the computer system resources to be used in an efficient manner. • Ability to evolve: An OS should be constructed in such a way as to permit the effective development, testing, and introduction of new system functions without interfering with service.

5 Connection with MySQL <?php $host= "localhost "; $user = "root ";
$passwd = " “; $database = “test”; $connect = mysql_connect($host, $user, $passwd); $DBSelect = mysql_select_db($database, $connect); If (!$connect || !$DBSelect) { $Status = "Not connected"; /*. mysql_error();*/ die('Could not connect: ' . mysql_error()); } else $Status = "Connected"; echo 'Connected successfully'; } ?>

6 Get data from MySQL <?php $host= "localhost"; $user = "root ";
$passwd = " “; $database = “test”; $tbl_name = “pet” mysql_connect($host, $user, $passwd) or die("cannot connect server "); mysql_select_db($database) or die("cannot select DB"); $result=mysql_query("SELECT * FROM pet"); while($rows = mysql_fetch_array($result)) { echo $rows['name'] . "\t“ . $rows['species'] . "<br>"; } mysql_close(); //close database ?>

7 Insert data to MySQL <?php $host= "localhost"; $user = "root ";
$passwd = " “; $database = “test”; $tbl_name = “pet” mysql_connect ($host, $user, $passwd) or die("cannot connect server "); mysql_select_db("$database") or die("cannot select DB"); $sql = “Insert Into $tbl_name (Name, species) VALUES (‘Polo', ‘Cat')"; $result = mysql_query ($sql); if($result) { echo "Successful"; echo "<BR>"; } mysql_close(); //close database ?>

8 Together – insert & retrieval
<?php $host= "localhost"; $user = "root "; $passwd = " “; $database = “test”; $tbl_name = “pet” mysql_connect ($host, $user, $passwd) or die("cannot connect server "); mysql_select_db("$database") or die("cannot select DB"); $sql=“Insert Into $tbl_name (Name, species) VALUES (‘Polo', ‘Cat')"; $result=mysql_query($sql); $result = mysql_query("SELECT * FROM $tbl_name"); while($rows = mysql_fetch_array($result)) { echo $rows[ 'name'] . "\t“ . $rows['species'] . "<br>"; } mysql_close(); //close database ?>

9 Summary PHP – client side language.


Download ppt "Remote hosts and web servers"

Similar presentations


Ads by Google