ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

10-4-2 ¸ê®ÆÀx¦s»Pª¬ºAÅã¥Ü

10-4-2 ¸ê®ÆÀx¦s»Pª¬ºAÅã¥Ü

10-4-2   ¸ê®ÆÀx¦s»Pª¬ºAÅã¥Ü
Àx¦s³ø¦WªÌ¸ê®Æªºaddpeople.phpµ{¦¡ºô­¶¨ä¥ô°È¦³¤T¶µ¡G
1.ÀËÅç¬ã°Q·|ªº¸ê®Æªí¬O§_¦s¦b¡A¦pªG¸Ó¬ã°Q·|¸ê®Æªí¤£¦s¦b¡A«h«Ø¥ß·sªº¬ã°Q·|¸ê®Æªí¡C
2.±N³ø¦WªÌ¸ê®Æ¼g¤J¸ê®Æ®w¡C
3.Åã¥Ü³ø¦Wª¬ºA»P°Ñ¥[ªÌ²M³æ¦Cªí³sµ²¡C

ª`·N¡G§O§Ñ¤F¥ý¦bMySQL Server¤¤«Ø¤@­Ó¦W¬°¡uAutoAct¡vªº¸ê®Æ®w³á¡I
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

ÀËÅç¸ê®Æªí¬O§_¦s¦b
¦b³ø¦WªÌ¸ê®Æ¼g¤J¬Y­Ó¬ã°Q·|¸ê®Æªí¤§«e¡A§Ú­Ì¥²¶·¥ý§PÂ_¤@¤U¸Ó¸ê®Æªí¬O§_¦s¦b¡A¦pªG¦s¦b´N¥i¥H±N³ø¦WªÌ¸ê®Æª½±µ¼g¤J¹ïÀ³ªº¸ê®Æªí¤¤¡A­Y¸Ó¸ê®Æªí¤£¦s¦b¡A«h¥²¶·¨Ï¥ÎSQL¤¤ªºDML«ü¥O«Ø¥ß¤@­Ó·s¬ã°Q·|¸ê®Æªí¡C

ÁÙ°O±o§Ú­Ì¬ã°Q·|¸ê®Æªíªº³W®æ§a¡]ªí10-1¡^¡I«Ø¥ß¸ê®ÆªíªºDML«ü¥O±Ô­z¦p¤U¡G
  1. CREATE TABLE [¬ã°Q·|¸ê®Æªí¦W] (
  2.         Name varchar (10) NOT NULL ,
  3.         Email varchar (50) NULL ,
  4.         Company varchar (50) NULL ,
  5.         Tel varchar (20) NOT NULL
  6. )
½Æ»s¥N½X
¦Óªí³æ¤¤ªº¤U©ÔÄæ¦ì¡yactname¡z©Ò¶Ç»¼ªº¸ê®Æ´N¬O«¥­Ì¬ã°Q·|ªº¸ê®Æªí¦WºÙ¡A©Ò¥H¦bPHPµ{¦¡¤¤§Ú­Ì±NDML«ü¥O±Ô­z²Õ¦X¦p¤U¡G
  1.     $SQL="Create Table " .
  2.     $¬ã°Q·|¸ê®Æªí¦W .
  3.     " (" .
  4.     "Name varchar(10) Not NULL," .
  5.     "Email varchar(50)," .
  6.     "Company varchar(50)," .
  7.     "Tel varchar(20) Not NULL" .
  8.     ")";
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

·s¬ã°Q·|¸ê®Æªíªº«Ø¥ß»P§_¡A¨ú¨M©ó¸ê®Æ®w¤¤ªº¦³µL¸Ó¬ã°Q·|¸ê®Æªíªº¦s¦b¡A­nÀËÅç¸ê®Æªí¬O§_¦s¦b¥i§Q¥Îmysql_list_tables()»Pmysql_tablename()¨ç¼Æ¡C
mysql_list_tables()¡G¦C¥X¸ê®Æ®w¤¤¥þ³¡ªº¸ê®Æªí¡C
  1. int mysql_list_tables ( string database_name [, int link_identifier])
½Æ»s¥N½X

  • database_name¡G«ü©w§Ú­Ì­n¾Þ§@ªº¸ê®Æ®w¦WºÙ¡C
  • link_identifier¡G³s½u¥N¸¹¡Amysql_list_tables()¨ç¼Æ¥u­t³d¨ú¦^§@¥Î¤¤¸ê®Æ®w¤ºªº¸ê®Æªí¦Cªí¡A¨Ã¨S¦³³sµ²¸ê®Æ®wªº¯à¤O¡A¦]¦¹¡Amysql_list_tables()¨ç¼Æ¥²¶·³z¹L¬Y­Ó¤w«Ø¥ß¨Ã§¹¦¨¸ê®Æ®w³sµ²ªº¡u³s½u¥N¸¹¡v¡A³o­Ó¡u³s½u¥N¸¹¡v¬O¥Ñmysql_connect()¨ç¼Æ©Ò«Ø¥ßªº¡A³o­Ó°Ñ¼Æ¥i¥H¤£«ü©w¡A¦bmysql_list_tables()¨ç¼Æ°õ¦æ®É·|¦Û°Ê§ä´M³Ìªñ¥Ñmysql_connect()¨ç¼Æ©Ò«Ø¥ßªº³s½u¡C


mysql_list_tables()¨ç¼Æ¨Ï¥Î°}¦C¶°¦Xªº¤è¦¡¨Ó¦Cªí¨ú¦^ªº¸ê®Æªí¦WºÙ¡C
mysql_tablename()¨ç¼Æ¡G¨ú¥Xµ²ªG¶°¤¤ªº¸ê®Æ®w©Î¸ê®Æªí¦WºÙ¡C
  1. int mysql_ tablename ( int result_identifier, int i)
½Æ»s¥N½X

  • int result_identifier¡Gmysql_list_tables()¡Bmysql_list_dbs()¨ç¼Æ©Ò¶Ç¦^¨Óªºµ²ªGID¡]µ²ªG¶°¡^¡C
  • i¡G¨ç¼Æ©Ò¶Ç¦^¨Óªºµ²ªGID¸Ìªº¯Á¤Þ¡C
  1. //ÀËÅç¸ê®Æªí¬O§_¦s¦b
  2. $testrs=mysql_list_tables("AutoAct");      
  3. if (!($Actname==mysql_tablename($testrs,$Actname)))
  4.    {
  5.     //¸ê®Æªí¤£¦s¦b«h«Ø¥ß
  6. //¥H¤U²¤
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¥²¶ñÄæ¦ì¬O§_¦³¸ê®Æ¿é¤J
¦b¸ê®Æªí³W¹º®É¡A§Ú­Ì§â©m¦W¡]Name¡^»PÁpµ¸¹q¸Ü¡]Tel¡^Äæ¦ì³]©w¬°¤@©w­n¦³¸ê®Æ¿é¤JªºÄæ¦ì¡]Not NULL¡^¡A¤]´N¬O»¡³ø¦W°Ñ¥[¬ã°Q·|ªÌ¤@©w­n¿é¤J¥Lªº©m¦W»P³sµ¸¹q¸Ü¡A¦pªG¨S¦³¸ê®Æ¿é¤Jªº¸Ü·|³y¦¨·s¼W¸ê®Æ¿ý®Éµo¥Í¿ù»~¡A©Ò¥H§Ú­Ì¥[¤J¤U¦Cªº§PÂ_±Ô­z¡G
  1. <?
  2. //§PÂ_¥²¶ñÄæ¦ì¸ê®Æ¬O§_¬°ªÅ¥Õ
  3. //­Y¥²¶ñÄæ¦ì¸ê®ÆªÅ¥Õ«hªð¦^³ø¦W­¶
  4. if (empty($_REQUEST["Name"]))
  5. {
  6. header("Location: index.php?msg=±z­è­è©m¦W¥¼¶ñ!!");
  7. exit();
  8. }
  9. else if(empty($_REQUEST["Tel"]))
  10. {
  11. header("Location: index.php?msg=±z­è­èÁpµ¸¹q¸Ü¥¼¶ñ!!");
  12. exit();
  13. }
  14. else
  15. {
  16. //±µ¦¬¨Ó¦Ûªí³æ¤¤ªº¥²¶ñÄæ¦ì¸ê®Æ
  17. $Name = $_REQUEST["Name"];
  18. $Tel = $_REQUEST["Tel"];
  19. }
½Æ»s¥N½X
¦pªG¥²¶·¿é¤J¸ê®ÆªºÄæ¦ì¨S¦³¿é¤J¸ê®Æ¡A«h±Nºô­¶Âà¦V¦^³ø¦W­º­¶index.php¡A¦P®É¶Ç»¼¿ù»~°T®§¡C

¹Ï10-24  ³ø¦W­º­¶Åã¥Ü¿ù»~°T®§¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¬d¬Ý¤w°Ñ¥[¤H­ûªº³sµ²³]­p¦P¼Ë¬O±Ä¥Î¡uªí³æ¡v¤è¦¡«Ø¥ß¡A³o­Óµ§ªÌ´N¤£¦A¦h»¡¤F¡A°O±o±NFORM¼ÐÅÒ¤¤ªºactionÄݩʳ]©w¬°listpeople.php§Y¥i¡C
addpeople.php
  1. <?
  2. //§PÂ_¥²¶ñÄæ¦ì¸ê®Æ¬O§_¬°ªÅ¥Õ
  3. //­Y¥²¶ñÄæ¦ì¸ê®ÆªÅ¥Õ«hªð¦^³ø¦W­¶
  4. if (empty($_REQUEST["Name"]))
  5. {
  6. header("Location: index.php?msg=±z­è­è©m¦W¥¼¶ñ!!");
  7. exit();
  8. }
  9. else if(empty($_REQUEST["Tel"]))
  10. {
  11. header("Location: index.php?msg=±z­è­èÁpµ¸¹q¸Ü¥¼¶ñ!!");
  12. exit();
  13. }
  14. else
  15. {
  16. //±µ¦¬¨Ó¦Ûªí³æ¤¤ªº¥²¶ñÄæ¦ì¸ê®Æ
  17. $Name = $_REQUEST["Name"];
  18. $Tel = $_REQUEST["Tel"];
  19. }

  20. //§PÂ_«D¥²¶ñÄæ¦ì'¤½¥q'¸ê®Æ¬O§_¬°ªÅ¥Õ
  21. if (empty($_REQUEST["Company"]))
  22. {
  23. $Company="";
  24. }
  25. else
  26. {
  27. $Company = $_REQUEST["Company"];
  28. }
  29. //§PÂ_«D¥²¶ñÄæ¦ì'E-Mail'¸ê®Æ¬O§_¬°ªÅ¥Õ
  30. if (empty($_REQUEST["Email"]))
  31. {
  32. $Email="";
  33. }
  34. else
  35. {
  36. $Email = $_REQUEST["Email"];
  37. }

  38. $Actname=$_REQUEST["Actname"];

  39. //³sµ²SQL Server
  40.     $conn = mysql_connect("localhost", "root", "12345a");
  41. //¿ï¾Ü¸ê®Æ®w
  42.     mysql_select_db("AutoAct", $conn);  
  43. //«ü©w´£¨ú¸ê®Æªº®Õ¹ï¦r¤¸ªí
  44.     mysql_query("set character set big5");
  45. //ÀËÅç¸ê®Æªí¬O§_¦s¦b
  46. $testrs=mysql_list_tables("AutoAct");      
  47. if (!($Actname==mysql_tablename($testrs,$Actname)))
  48.    {
  49.     //¸ê®Æªí¤£¦s¦b«h«Ø¥ß
  50.     $SQL="Create Table " .
  51.     $Actname .
  52.     " (" .
  53.     "Name varchar(10) Not NULL," .
  54.     "Email varchar(50)," .
  55.     "Company varchar(50)," .
  56.     "Tel varchar(20) Not NULL" .
  57.     ")";
  58.     mysql_query($SQL);
  59.    }
  60.          
  61. //«Ø¥ß¬d¸ß¦r¦ê¥Î¥H§PÂ_¬O§_­«½Æ³ø¦W
  62. $SQL="Select name From " . $Actname . " Where name='" . $Name . "'";
  63. $RS=mysql_query($SQL);

  64. if (!mysql_fetch_array($RS))
  65. {
  66. //¦pªG©|¥¼³ø¦W«h¼g¤J³ø¦WªÌ¸ê®Æ
  67. $sql = "Insert Into " . $Actname . " (name, Email, company, tel) Values ('";
  68. $sql = $sql . $Name . "','";
  69. $sql = $sql . $Email . "','";
  70. $sql = $sql . $Company . "','";
  71. $sql = $sql . $Tel . "')";
  72. mysql_query($sql);
  73. $msg="§A¤w¸g¶¶§Q§¹¦¨<font color=#FF3300>" . $Actname . "</font>¬ã°Q·|³ø¦W";
  74. }
  75. else  //­«½Æ³ø¦W
  76. {
  77. $msg="§A¤w¸g³ø¦W¹L<font color=#FF3300>" . $Actname . "</font>¬ã°Q·|";
  78. }

  79. mysql_close();
  80. ?>

  81. <html>
  82. <head>
  83. <meta http-equiv="Content-Type" content="text/html; charset=big5">
  84. <title>½u¤W³ø¦W</title>
  85. </head>
  86. <body>
  87. <p align="center"><img border="0" src="tit.gif" width="231" height="40"></p>
  88. <p align="center"><?=$msg;?></p>
  89. <hr width="80%" color="#FF9900">
  90. <form method="POST" action="listpeople.php">
  91. <p align="center">
  92. <input type="hidden" value="<?=$Actname;?>" name="Actname">
  93. <input type="submit" value="¬d¬Ý¤w°Ñ¥[¤H­û"
  94. style="background-color: #008000; color: #FFFFFF; border-style: groove">
  95. </p></form>
  96. </body>
  97. </html>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¬ã°Q·|³ø¦W¤H­û²M³æºô­¶¡Glistpeople.php
  1. <?
  2. //±µ¦¬¬d¸ß¬ã°Q·|¸ê®Æ
  3.     $Actname=$_REQUEST["Actname"];
  4. //³sµ²SQL Server
  5.     $conn = mysql_connect("localhost", "root", "12345a");
  6. //¿ï¾Ü¸ê®Æ®w
  7.     mysql_select_db("AutoAct", $conn);
  8. //«ü©w´£¨ú¸ê®Æªº®Õ¹ï¦r¤¸ªí
  9.     mysql_query("set character set big5");  
  10. //«Ø¥ßSQL©R¥O¦r¦ê
  11.     $SQL="Select * From " . $Actname;
  12. //±N¦^¶Çµ²ªG¦s©ñ©óÅܼƤ¤
  13.     $datalist=mysql_query($SQL);
  14. //¨ú±oÄæ¦ì¼Æ¶q
  15.     $fieldnum=mysql_num_fields($datalist);
  16. ?>

  17. <HTML>
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=big5">
  20. <title><?=$Actname;?>¬ã°Q·|³ø¦W¤H­û²M³æ</title>
  21. </head>
  22. <BODY>
  23. <p align="center">
  24. <img border="0" src="../tit.gif">
  25. <p Align="Center">
  26. <font color="#FF9900"><?=$Actname;?>¬ã°Q·|³ø¦W¤H­û²M³æ</font></p>
  27. <div align="center">
  28.   <center>
  29. <TABLE Border=1 Cellspacing=1 bordercolor="#800000">
  30.      
  31. <?
  32. //¦C¥XÄæ¦ì©ïÀY
  33. echo "<tr>";     
  34.       for ($x=0 ;$x<$fieldnum;$x++)
  35.          {
  36.           echo "<td>" . mysql_field_name($datalist,$x) . "</td>";
  37.          }
  38. echo "</tr>";   
  39. //¦C¥XÄæ¦ì¸ê®Æ
  40.       //±N¸ê®Æ¿ýÂà´«¬°Äæ¦ì°}¦C¶°¦X
  41.       while ($fielddatas=mysql_fetch_array($datalist))
  42.           {
  43.              //¿é¥XÄæ¦ì¸ê®Æ
  44.              echo "<tr>";
  45.              for ($x=0;$x<$fieldnum;$x++)
  46.                 {
  47.                  echo "<td>" . $fielddatas[$x] . "</td>";
  48.                 }
  49.              echo "</tr>";  
  50.           }
  51. ?>

  52. </TABLE>   
  53.   </center>
  54. </div>
  55. <p align="center"><font size="2">
  56. <a href="index.php">ªð¦^µn¿ý­¶</a></font></p>
  57. </html>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

§A¦n, ¤p»xª©¥D, ²{¦b§Ú¥Î¤FPHP6¤§«á, addpeople.php
ªº"$testrs=mysql_list_tables("AutoAct"); " ¤§«á§Ú¦b
©x¤èPHP«ü¥Ü§ï¤Fmysql_list_tables()¦p¤U:
$autoact='autoact';
$SQL="SHOW TABLES FROM $autoact";
$testrs=mysql_query($SQL);

¦ý°õ¦æ«á¥X¤F
Warning: mysql_tablename() [function.mysql-tablename]: Unable to jump to row 0 on MySQL result index 4 in C:\AppServ\www\addpeople.php on line 50

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\addpeople.php on line 66

·Q½Ð±Ð¤p»xª©¥D¤j¤j§Ú¸Ó«ç¼Ë¿ì©O?
Man

TOP

¤w¸g¸Ñ¨M¤F, ­ì¨Ó¬O§Ú"¼g¤J³ø¦WªÌ¸ê®Æ"º|¤F¤@¨Ç²Å¸¹, ÁÂÁÂ!
Man

TOP

        ÀR«ä¦Û¦b : ¥Í®ð¡A´N¬O®³§O¤Hªº¹L¿ù¨ÓÃg»@¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD