6 $smarty->assign('data2','Last Name');
7 $smarty->assign('data3','email');
8 $smarty->display('insert.tpl');
?>
添加将在insert.tpl 使用的变量.调用模板insert.tpl .
save.php
1 <?
2 require_once('DB/DataObject.php');
3 require('configDB.php');
4 $user = DB_DataObject::factory('user');
5 $user->first_Name = $x;
6 $user->last_Name = $y;
7 $user->email = $z;
8 $user_Id = $user->insert();
9 $user->update();
10 echo "<script>location.href='index.php'</script>";
11 ?>
This script saves data by using a PEAR::DataObject for the user table. Line 2 loads the class DataObject, and
line 3 calls configdb.php to connect to the database. Line 4 creates an instance of a user object (see User.php).
Lines 5 through 7 pass the variables collected from the form in insert.tpl ($x, $y, and $z) in order to save the
data in the database. The primary key of the table is an autoincrement column, so it doesn't need a value there.
Line 8 inserts the object, and line 9 carries out an update.
view.php
1 <?
2 require_once('DB/DataObject.php');
3 require('configDB.php');
4 require("include.php");
5 $user = DB_DataObject::factory('user');
6 $user->find();
7 while ($user->fetch()) {
8 
| 对此文章发表了评论 |
