我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > PHP专区 > php深入/精通 > 一个对数据库进行操作的程序(之二)
热门文章排行
热门文章排行 检查email地址格式的代码(01-11)
PHP操作文件问答(01-11)
PHP安装攻略:安装并配置PHP(10-23)
PHP的十个高级技巧 4(10-23)
PHP控制语句(10-12)
精采文章排行
精采文章排行 PHP连接MYSQL的两种方法(11-15)
PHP和MySQL开发的8个技巧(10-23)
PHP安装攻略:安装并配置PHP(10-23)
php+mysql扎实个人基本功(10-23)
PHP编程常用技巧四则(10-23)
技术专题推荐
网管论坛交流
 

一个对数据库进行操作的程序(之二) 

作者:佚名   来源:本站教程   点击:   日期:2007-01-11

以下粘贴出各个页面的源代码:

db.func:

<?
function GetRows( $Database, $Query ) {
   mysql_connect ("ftp", "root", "");
   $db = mysql_select_db( $Database );
   if ( ! $db ) {
      echo "无法连结数据库!";
      exit;
   }

   $rows = mysql_query( $Query );
   if ( ! $rows ) {
      echo "SQL指令错误!";
      exit;
   }
   return $rows;
}

function ConnectDatabase( $Database ) {
   mysql_connect ("ftp", "root", "");
   $db = mysql_select_db( $Database );
   if ( ! $db ) {
      echo "无法连结数据库!";
      exit;
   }
}
?>

cratetable.php:

<?
function CreateTable() {
   $link = mysql_connect ("ftp", "root", "");
   $db = mysql_select_db("pcadmin");
   if ( ! $db ) {
      echo "连接到数据库失败!";
      exit;
   }
   $rows = mysql_query("select * from Profile");
   if ( ! $rows ) {
      $sql = "Create Table Profile (ID integer auto_increment primary key,Name char(255),Produce char(255),Lianluo char(255),Tel integer(15),Email char(255))";
      mysql_query($sql);
   }
  
   $rows = mysql_query("select * from Aplication");
   if ( ! $rows ) {
      $sql = "Create Table Aplication(Name char(255) primary key,IP char(255),Ap char(255),Directory char(255))";
      mysql_query($sql);
   }
   mysql_close ($link);
}
CreateTable();
?>

input.htm:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>輸入表單</title>
<style type="text/css">
<!--
.INPUT {
 border: 1px solid #003C74;
}
.font {
 font-family: "新宋体";
 font-size: 14px;
 color: #0000FF;
 font-weight: lighter;
}
.table {
 border: 1px solid #000000;
}
.title {
 font-family: "新宋体";
 font-size: 14px;
 color: #FF0000;
}
-->
</style>
</head>

<body><h3><center class="title">輸入表單
</center><hr size="1" noshade>
</h3>

<form name="form1" method="post" action="insert.php">
<table width="400"align=center>
 <tr>
    <th scope="row"><div align="left" class="font">主機名稱</div></th>
    <td><input name="Name" type="text" class="input"></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="font">生產廠商</div></th>
    <td><input name="Produce" type="text" class="INPUT"></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="font">聯絡人</div></th>
    <td><input name="Lianluo" type="text" class="INPUT">      </td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="font">聯絡人電話</div></th>
    <td><input name="Tel" type="text" class="INPUT"></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="font">聯絡人郵箱</div></th>
    <td><input name="Email" type="text" class="INPUT"></td>
  </tr>
  <tr>
    <th scope="row"><p align="left" class="font">IP Address</p>
      </th>
    <td><input name="IP" type="text" class="INPUT"></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="font">應用名稱</div></th>
    <td><input name="Ap" type="text" class="INPUT"></td>
  </tr>
  <tr>
    <th align="left" valign="top" scope="row"><div align="left" class="font">配置文件</div></th>
    <td><textarea name="Directory" cols="40" rows="5" class="INPUT" clums="15"></textarea></td>
  </tr>
  <tr>
    <th scope="row"><input name="Send" type="submit" class="INPUT" value="提交"></th>
    <td><input name="Submit" type="reset" class="INPUT" value="重寫">
      <a href="show.php">查看记录</a></td>
  </tr>
</table>

</form><hr size="1" noshade>
<p>&nbsp;</p>
</body>
</html>

insert.php:

<HTML>
<style type="text/css">
<!--
.font {
 font-family: "新宋体";
 font-size: 14px;
 font-weight: lighter;
 color: #FF0000;
}
-->
</style>
<BODY bgcolor="#FFFFFF">
<H3><a href="show.php" class="font">成功輸入一筆資料去看看</a> 
<HR></H3>
<?
include("../db.func");

if ( !empty($Send) ) {
   ConnectDatabase( "pcadmin" );
   $sql = "insert into Profile(Name,Produce,Lianluo,Tel,Email) values('$Name','$Produce','$Lianluo','$Tel','$Email')";
  
   mysql_query( $sql );
    }
?>
</BODY>
</HTML>

show.php:

<?
function ShowOnePage( $rows, $No ) {
  mysql_data_seek( $rows, $No );
 

  echo "<TABLE Border=1 Align=Center bordercolordark='#ffffff'  bordercolorlight='#000000' cellpadding='3' cellspacing='0' >";
  echo "<TR BgColor=Cyan>";
  while ( $field = mysql_fetch_field($rows) ) {
     echo "<TD>" . $field->name . "</TD>";
  }
  echo "</TR>";
  $nums = mysql_num_rows($rows);
  for ( $I=1; $I <=10; $I++ ) {
     if ( $row = mysql_fetch_row($rows) ) {
          for ( $K=0 ; $K < count($row); $K++ ) {
           echo "<TD Align=Right>" . $row[$K] . "</TD>";
        }
        echo "</TR>";
     }
  }
  echo "</TABLE>";
}
?>

<HTML>
<style type="text/css">
<!--
.title {
 color: #FF0000;
 font-family: "新宋体";
 font-size: 14px;
}
.body {
 font-family: "新宋体";
 font-size: 12px;
 font-weight: lighter;
 color: #0000FF;
}
-->
</style>
<title>伺服器清单</title><BODY bgcolor="#FFFFFF">
<H2 ALIGN=CENTER><span class="title">伺服器清單</span>
  <HR size="1" noshade color="#0000ff" class="hr" >
</H2>
<?
  include("../db.func");
  $rows = GetRows( "pcadmin", "Select * From Profile" );

  $num = mysql_num_rows($rows);


文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·将OICQ数据转成MYSQL数据 ·用PHP实现ODBC数据分页显示一例
·php生成WAP页面 ·PHP与Javascript的两种交互方式
·PHP+Javascript模拟Matrix画面 ·WHOIS类的修改版

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。