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

11-1-2 ¯d¨¥ºô­¶»P¯d¨¥Àx¦s

11-1-2 ¯d¨¥ºô­¶»P¯d¨¥Àx¦s

11-1-2   ¯d¨¥ºô­¶»P¯d¨¥Àx¦s
·í§Ú­Ì­n¦bºô­¶¤¤´£¨Ñ¤@­Ó¥i¥HÅýºô¤Íµoªí·N¨£©Î¤Ï¬Mªº¯d¨¥ªO®É¡A¥²¶·¥ý³]­p¤@­Ó¡y·N¨£µoªíªí³æ¡]addmsg.php¡^¡z¡AÅýºô¤Í¥i¥H¦b¤W­±µoªí·N¨£¡A¨Ã¥B­n¯à±N³o¨Ç·N¨£¸ê®Æ°eµ¹§Ú­Ì³B²z¯d¨¥¸ê®ÆªºPHPµ{¦¡¡yadd.php¡z¨Ó°O¿ý¥H¤Î³B²z³o¨Ç·N¨£¸ê®Æ¡C
  ²{¦b½Ð¥´¶}addmsg.phpºô­¶¡A¨Ó¤F¸Ñ¤@¤U¦p¦ó»s§@¤@­Ó¥i¥HÅýºô¤Í¦b¤W­±µoªí·N¨£ªºªí³æ¡G

¹Ï11-5  addmsg.phpºô­¶¡C

½s¸¹

Äæ¦ì

Äæ¦ì¦WºÙ

ªí³æ¤¸¥ó

¢°

¯d¨¥¥DÃD

subject

³æ¦æ¤å¦r¤è¶ô

¢±

±zªº¤j¦W

parent

³æ¦æ¤å¦r¤è¶ô

¢²

E-Mail

email

³æ¦æ¤å¦r¤è¶ô

¢³

¥Nªí¹Ï§Î

pic

¿ï¾Ü¶s

¢´

¯d¨¥©Ê½è

personal

¤U©Ô¦¡¥\¯àªí

¢µ

¯d¨¥¤º®e

memo

¦h¦æ¤å¦r¤è¶ô

¢¶

°e¥X·N¨£

Submit

«ö¶s

¢·

²M°£­«¼g

¡þ

«ö¶s



¡y¯d¨¥¥DÃD¡zºô­¶±Ô­z¼ÐÅÒ
  1. <input type="text" name="subject" size="50" maxlength="20">
½Æ»s¥N½X
¡y±zªº¤j¦W¡zºô­¶±Ô­z¼ÐÅÒ
  1. <input type="text" name="parent" size="20" maxlength="20">
½Æ»s¥N½X
¡yE-Mail¡zºô­¶±Ô­z¼ÐÅÒ
  1. <input type="text" name="email" size="35" maxlength="40">
½Æ»s¥N½X
¡y¥Nªí¹Ï§Î¡zºô­¶±Ô­z¼ÐÅÒ
  1. <input type="radio" name="pic" value="1" checked >
  2. <img src="1.gif">
  3. <input type="radio" name="pic" value="2"><img src="2.gif">
  4. <input type="radio" name="pic" value="3"><img src="3.gif">
  5. <input type="radio" name="pic" value="4"><img src="4.gif">
  6. <input type="radio" name="pic" value="5"><img src="5.gif">
  7. <input type="radio" name="pic" value="6"><img src="6.gif">
  8. <input type="radio" name="pic" value="7"><img src="7.gif">
  9. <input type="radio" name="pic" value="8"><img src="8.gif">
  10. <input type="radio" name="pic" value="9"><img src="9.gif">
  11. <input type="radio" name="pic" value="10"><img src="10.gif">
½Æ»s¥N½X
¡y¯d¨¥©Ê½è¡zºô­¶±Ô­z¼ÐÅÒ
  1. <select name="personal" size="1">  
  2.   <option value="0" selected>¤j®a¨Ó°Q½×</option>
  3.   <option value="1">¥uµ¹ªO¥D¬Ý</option>
  4. </select>
½Æ»s¥N½X
¡y¯d¨¥¤º®e¡zºô­¶±Ô­z¼ÐÅÒ
  1. <textarea name="memo" cols="50" rows="4" ></textarea>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

½Ð¯S§Oª`·N¡G§Ú­Ìªí³æªº¦WºÙ¬°¡yAddmsg¡z¡A¦Óªí³æ¤º®e¸ê®Æªº¶Ç°e¤è¦¡¬°¡yPost¡z¡A³B²z·N¨£¸ê®ÆªºPHPµ{¦¡¬O¡yadd.php¡z.
  1. <form name="addmsg" method="POST" action="add.php">
½Æ»s¥N½X
§¹¾ãºô­¶¤º®e¦Cªí¦p¤U¡G
addmsg.php
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=big5">
  4. <title>³Â»¶®a±Ú¯d¨¥ªO</title>
  5. </head>
  6. <body>
  7. <div align="center">
  8. <p align="center">
  9. <font size="2">
  10. <img src="title.gif">
  11. </font>
  12. <br>
  13. <font size="2"><a href="guest.php">
  14. <img border="0" src="team2.gif" align="absmiddle">
  15. ¬Ý¬Ýºô¤Í­Ìªº·N¨£<img border="0" src="team2.gif" align="absmiddle">
  16. </a></font> </div>
  17. <form name="addmsg" method="POST" action="add.php">
  18. <div align="center">
  19. <table border="1" cellspacing="0" style="border-collapse: collapse"
  20. bordercolor="#FFFFFF" cellpadding="0">
  21. <tr><td bgcolor="#339933" align="center" valign="middle" width="147">
  22. <font color="#FFFFFF" size="2">¯d¨¥¥DÃD</font></td>
  23. <td height="25" bgcolor="#E8FFE8"><font size="2">
  24. <input type="text" name="subject" size="50" value maxlength="20">
  25. </font></td></tr> <tr>
  26. <td bgcolor="#339933" align="center" valign="middle" width="147">
  27. <font color="#FFFFFF" size="2">±zªº¤j¦W</font></td>
  28. <td height="25" bgcolor="#E8FFE8"><font size="2">
  29. <input type="text" name="name" size="20" maxlength="20"></font></td>
  30. </tr>
  31. <tr>
  32. <td bgcolor="#339933" align="center" valign="middle" width="147">
  33. <font color="#FFFFFF" size="2">E-Mail</font></td>
  34. <td height="25" bgcolor="#E8FFE8"><font size="2">
  35. <input type="text" name="email" size="35" maxlength="40"></font></td>
  36. </tr>
  37. <tr>
  38. <td bgcolor="#339933" align="center" height="27" valign="middle" width="147">
  39. <font size="2" color="#FFFFFF">¥Nªí¹Ï§Î</font></td>
  40. <td height="27" bgcolor="#E8FFE8">
  41. <font size="2">
  42. <input type="radio" name="pic" value="1" checked ><img src="1.gif">
  43. <input type="radio" name="pic" value="2"><img src="2.gif">
  44. <input type="radio" name="pic" value="3"><img src="3.gif">
  45. <input type="radio" name="pic" value="4"><img src="4.gif">
  46. <input type="radio" name="pic" value="5"><img src="5.gif">
  47. <input type="radio" name="pic" value="6"><img src="6.gif">
  48. <input type="radio" name="pic" value="7"><img src="7.gif">
  49. <input type="radio" name="pic" value="8"><img src="8.gif">
  50. <input type="radio" name="pic" value="9"><img src="9.gif">
  51. <input type="radio" name="pic" value="10"><img src="10.gif">
  52. </font>
  53. </td>
  54. </tr>
  55. <!--¨p¤H¯d¨¥©Î¤½¶}-->
  56. <tr>
  57. <td bgcolor="#339933" align="center" width="147">
  58. <font color="#FFFFFF" size="2">¯d¨¥©Ê½è</font></td>
  59. <td bgcolor="#E8FFE8">
  60. <font size="2">
  61. <select name="personal" size="1">
  62. <option value="0" selected>¤j®a¨Ó°Q½×</option>
  63. <option value="1">¥uµ¹ªO¥D¬Ý</option>
  64. </select>
  65. </font>
  66. </td>
  67. </tr>
  68. <!--¯d¨¥¤º®eÄæ¦ì-->
  69. <tr>
  70. <td bgcolor="#339933" align="Center" height="98" valign="middle" width="147">
  71. <font color="#FFFFFF" size="2">¯d¨¥¤º®e¡G</font>
  72. </td>
  73. <td height="98" valign="middle" bgcolor="#E8FFE8">
  74. <font size="2">
  75. <textarea name="memo" cols="50" rows="4" ></textarea>
  76. </font>
  77. </td></tr><tr><td align="Center" colspan="2">
  78. <font size="2"><input type="submit"value="°e¥X·N¨£">
  79. <input type="reset" value="­«¶ñ¸ê®Æ"></font></td>
  80. </tr></table></div>
  81. </form></center>
  82. </body></html>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¯d¨¥³B²zµ{¦¡
·íºô¤Í¦b¡u·N¨£µoªíªí³æ¡v¤¤¶ñ¼g¦n¬ÛÃö¸ê®Æ¡AµM«á«ö¤U¡u°e¥X·N¨£¡v«ö¶s¡Aªí³æ¤¤ªº¸ê®Æ¤º®e´N·|¥H¡yPOST¡zªº¤è¦¡¥ÑSEVERºÝŪ¨ú¡A¦]¬°§Ú­Ì¦bªí³æ¶Ç°eªºAction°Ñ¼Æ«ü©wServerºÝ³B²z¦¹¤@ªí³æ¸ê®Æ¤º®eªºµ{¦¡¬°¡yadd.php¡z¡A¦]¦¹§Ú­Ì´N¥²¶·¨Ó¼¶¼g¯à°÷³B²z³o¨Ç·N¨£¸ê®ÆªºPHPµ{¦¡¡yadd.php¡z¡C
¦b³o­Ó³B²z·N¨£¸ê®ÆªºPHPµ{¦¡¡A§Ú­Ì¥i¤À¬°¤U¦C´X­Ó³¡¤À¡G

1.±µ¦¬¨Ó¦Û¡y·N¨£µoªíªí³æ¡z¤¤ªº¦UÄæ¦ì¸ê®Æ
­n±Nºô¤Íµo¨¥¸ê®Æ§@«áÄò³B²z¤Î±N³o¨Ç¸ê®Æ¤º®e¦s¤J¸ê®Æ®w¤§«e¡A§Ú­Ì¥²¶·¥ý§â¦U­ÓÄæ¦ìªº¸ê®Æ©Ó±µ¤U¨Ó¡G
  1. //±µ¦¬addmsg.php¶Ç¨Óªº¸ê°T
  2. $subject=$_REQUEST["subject"];
  3. $name = $_REQUEST["name"];
  4. $email = $_REQUEST["email"];
  5. $pic=$_REQUEST["pic"];
  6. $memo=nl2br($_REQUEST["memo"]);
  7. $personal = $_REQUEST["personal"];
½Æ»s¥N½X
¨ä¤¤¤ñ¸û¯S§Oªº¬O¯d¨¥¤º®e¡umemo¡vªº¸ê®Æ³B²z¡A¯d¨¥¤º®eÄæ¦ì¬O¦h¦æ¤å¦r¿é¤J¤¸¥ó¡A·í§Ú­Ì±N¿é¤J©ó¦h¦æ¤å¦r¿é¤J¤¸¥óªº¸ê®ÆÅã¥Ü¥X¨Ó®É¡A·|¦³¤@­ÓÂ_¦æªº°ÝÃD¡A¿é¤J¸ê®Æ®É¡A¦b¦h¦æ¤å¦r¿é¤J¤¸¥ó¤¤«ö¤U¡uEnter¡v·|¦³´«¦æªº®ÄªG¡AÁöµM¦bªí­±¤W¬Ý¤£¨ì¥ô¦óªº´«¦æ¦r¤¸¡A¦ý¹ê»Ú¤W«o¯u¹ê¦s¦bµÛ¤@­Ó´«¦æ¦r¤¸¡u\r\n¡v¡A³o­Ó´«¦æ¦r¤¸¦b§Ú­Ì¿é¥X¨ìÂsÄý¾¹®É¨Ã¤£·|¦³´«¦æªº®ÄªG¡A¦]¦¹¡A¿é¥X®ÉÀ³¥ý¨Ï¥Î¡ustr_replace()¡v¨ç¼Æ±N³o­Ó´«¦æ¦r¤¸¡u\r\n¡v´À´«¦¨¡u<Br>¡vªºHTML¼ÐÅҲŸ¹¡C

2.«Ø¥ßchgStr¨ç¼Æ
¥Ñ©óºô¤Íµo¨¥ªº¸ê®Æ¥²¶·¥H³æ¤Þ¸¹¬A°_¨Óªºªº«¬¦¡»PInsert Into«ü¥Oµ²¦X¦b¤@°_¡A¦pªGºô¤Íµo¨¥ªº¸ê®Æ¤º®e­ì¥»´N¨Ï¥Î¤F³æ¤Þ¸¹¡A±N·|¨Ïµ{¦¡²£¥Í¿ù»~¡A¦]¦¹§Ú­Ì´N¥ý¦Û¦æ«Ø¥ß¤@­ÓchgStr¨ç¼Æ¡A±Nºô¤Íµo¨¥ªº¸ê®Æ¤º®e¥ý¸g¹LchgStr¨ç¼Æ¹LÂo¡A­Y¸ê®Æ¤º®e§t¦³³æ¤Þ¸¹«h±N³æ¤Þ¸¹Âà´«¬°Âù¤Þ¸¹¡G
  1. //±N³æ¤Þ¸¹¸m´«¬°Âù¤Þ¸¹
  2. Function chgStr($data)
  3. {
  4.    $chgStr = "'" . str_replace("'", "''", $data) . "'";
  5.    return $chgStr;
  6. }
½Æ»s¥N½X
3.«Ø¥ß»P¸ê®Æ®wªº³sµ²
­n±N©Ó±µ¤U¨Óªº¦U­ÓÄæ¦ìªº¸ê®Æ¼g¤J¸ê®Æ®w¤§«e¡A¥²¶·¥ý«Ø¥ß»P¸ê®Æ®wªº³sµ²¡Amysql_connect()»Pmysql_select_db()¨ç¼Æªº¨Ï¥Î¡A¤§«e§Ú­Ì¤w¸g½Í¹L¤£¦bÂب¥¡G
  1. //³sµ²SQL Server
  2.     $conn = mysql_connect("127.0.0.1", "sa", "12345");
  3. //¿ï¾Ü¸ê®Æ®w
  4.     mysql_select_db("Message", $conn);
  5. //«ü©w´£¨ú¸ê®Æªº®Õ¹ï¦r¤¸ªí
  6.     mysql_query("set character set big5");
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

4.«Ø¥ß·s¼W¸ê®Æ¿ýªºInsert Into«ü¥O
Insert Into«ü¥O±Ô­z®æ¦¡¡G
  1. Insert Into  ¸ê®Æªí¦W  (Äæ¦ì¦W) values (Äæ¦ì­È)
½Æ»s¥N½X
³oºØ´¡¤J·s¸ê®Æ¿ýªº®æ¦¡¤S¥i¤À¬°¨âºØ§Î¦¡¡G
³v¤@±NÄæ¦ì­È³]©wµ¹¬Û¹ïÀ³ªºÄæ¦ì¡AµM«á¦A·s¼W¦Ü¸ê®Æªí¤¤¡A¨Ò¦p¡G
0.png
¥t¤@ºØ¤è¦¡»P¤W¤@ºØ®æ¦¡¹p¦P¡A¦ý¬O¬Ù²¤¤FÄæ¦ì¦WºÙ¡G
1.png
«Øij¾¨¶qÁקK¨Ï¥Î²Ä¤GºØ¤è¦¡¡A¦]¬°¤Ö¤FÄæ¦ì¹ïÀ³«Ü®e©öµo¥Í¸ê®Æ»~¶ñªº±¡ªp¡I

«Ø¥ß»P¸ê®Æ®wªº³sµ²«á¡A§Ú­Ì­º¥ý²Õ¦X±N·s¼W¸ê®Æ¿ýªºInstert Into«ü¥O¡AµM«á¦A¼g¤J¸ê®Æ®wÀɮפ¤¡G
  1. //±N¸ê®Æ¼g¤J¸ê®Æ®w
  2. $sql = "Insert Into allmessage (ºô¤Í©m¦W, ¯d¨¥¥DÃD, Ápµ¸«H½c, ¯d¨¥¤º®e, ¨p¤H¤½¶}, ¹Ï§Î, ¯d¨¥®É¶¡) Values (";
  3. $sql = $sql . chgStr($name) . ",";
  4. $sql = $sql . chgStr($subject) . ",";
  5. $sql = $sql . chgStr($email) . ",";
  6. $sql = $sql . chgStr($memo) . ",";
  7. $sql = $sql . chgStr($personal) . ",";
  8. $sql = $sql . $pic . ",'";
  9. $sql = $sql . date("Y-m-j H:i:s") . "')";
  10. mysql_query($sql);
½Æ»s¥N½X
5¡BÂà¦V¦ÜÅã¥Ü¯d¨¥·N¨£ªººô­¶guest.php
    ·íºô¤Íµo¨¥ªº¸ê®Æ¤º®e³B²z§¹²¦¨ÃÀx¦s¦Ü¸ê®Æ®wÀɮפ¤«á¡A§Ú­Ì«h¥²¶·±Nºô­¶Âà¦V¦ÜÅã¥Ü¯d¨¥·N¨£ªººô­¶guest.php¡A¦p¦¹¤@¨Ó¡Aµo¨¥ªººô¤Í´N¥i¬Ý¨£¥Lªºµo¨¥¬O§_¤w¸g¶¶§Qªºµn¿ý¡G
  1. //±Nºô­¶Âà¦V¦ÜÅã¥Ü¯d¨¥·N¨£ªººô­¶guest.php
  2. header("Location: guest.php");
½Æ»s¥N½X
add.php
  1. <?
  2. //±µ¦¬addmsg.php¶Ç¨Óªº¸ê°T
  3. $subject=$_REQUEST["subject"];
  4. $name = $_REQUEST["name"];
  5. $email = $_REQUEST["email"];
  6. $pic=$_REQUEST["pic"];
  7. $memo=nl2br($_REQUEST["memo"]);
  8. $personal = $_REQUEST["personal"];

  9. //³sµ²MySQL Server
  10.     $conn = mysql_connect("localhost", "root", "12345a");
  11. //¿ï¾Ü¸ê®Æ®w
  12.     mysql_select_db("Message", $conn);
  13. //«ü©w´£¨ú¸ê®Æªº®Õ¹ï¦r¤¸ªí
  14.     mysql_query("set character set big5");   

  15. //±N³æ¤Þ¸¹¸m´«¬°Âù¤Þ¸¹
  16. Function chgStr($data)
  17. {
  18.    $chgStr = "'" . str_replace("'", "''", $data) . "'";
  19.    return $chgStr;
  20. }

  21. //±N¸ê®Æ¼g¤J¸ê®Æ®w
  22. $sql = "Insert Into allmessage (ºô¤Í©m¦W, ¯d¨¥¥DÃD, Ápµ¸«H½c, ¯d¨¥¤º®e, ¨p¤H¤½¶}, ¹Ï§Î, ¯d¨¥®É¶¡) Values (";
  23. $sql = $sql . chgStr($name) . ",";
  24. $sql = $sql . chgStr($subject) . ",";
  25. $sql = $sql . chgStr($email) . ",";
  26. $sql = $sql . chgStr($memo) . ",";
  27. $sql = $sql . chgStr($personal) . ",";
  28. $sql = $sql . $pic . ",'";
  29. $sql = $sql . date("Y-m-j H:i:s") . "')";
  30. mysql_query($sql);

  31. //±Nºô­¶Âà¦V¦ÜÅã¥Ü¯d¨¥·N¨£ªººô­¶guest.php
  32. header("Location: guest.php");
  33. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : §Ú­Ì­n°µ¦nªÀ·|ªºÀô«O¡A¤]­n°µ¦n¤º¤ßªºÀô«O¡C
ªð¦^¦Cªí ¤W¤@¥DÃD