¼ÁÌä
-
¥Õ¥ê¡¼ PHP+MySQL
¥Æ¡¼¥Ö¥ë¤Ë¥Ç¡¼¥¿¤òÄɲäǤ¤Ê¤¤ -
ËÜʸ¡§
ÅöÊý½é¿´¼Ô¤Ç¤¹¡£
¡¡¥Æ¡¼¥Ö¥ë¤Ë¥Ç¡¼¥¿¤òľÀÜ¥³¡¼¥É¤Ç¤ÏÄɲäǤ¤Þ¤¹¤¬¡¢¥Õ¥©¡¼¥à¤«¤é¤Î¥Ç¡¼¥¿¤Ç¤Ï¤Ê¤¼¤«ÄɲäǤ¤Þ¤»¤ó¡£º£¸½ºß¤Ï¥¨¥é¡¼¤Ë¤â¤Ê¤Ã¤Æ¤¤¤Þ¤»¤ó¡£ÄɲÃÉôʬ¤Î¥³¡¼¥É¤Ï
try {
$dbh = new PDO($dsn, $username, $password);
// Àܳ¤ò»ÈÍѤ¹¤ë
//$sql = "INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
// ($_POST["meiboid"],$_POST["simei"],$_POST["ikajyusyo"],$_POST["todouhukencode"])";
$Meiboid = $_POST["meiboid"];
$Simei = $_POST["simei"];
$Ikajyusyo = $_POST["ikajyusyo"];
$Todouhukencode = $_POST["todouhukencode"];
$sql = "INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
((int)$Meiboid, (string)$Simei, (string)$Ikajyusyo, (int)$Todouhukencode)";
//print $_POST["meiboid"] . $_POST["simei"] . $_POST["ikajyusyo"] . $_POST["todouhukencode"] . "<BR>";
//print $Meiboid . $Simei . $Ikajyusyo . $Todouhukencode . "<BR>";
$stmt= $dbh->query( $sql);
$sql = 'select id, namae, jyusyo from meibo';
$stmt= $dbh->query( $sql);
echo "<table>\n";
¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÀܳ¤Èɽ·Á¼°¤Îprint¤Ï¾Êά¤·¤Æ¤Þ¤¹¡£¥¢¥¤¥Æ¥à¤ò¥¥ã¥¹¥È¤·¤Æ¸«¤Æ¤â´Ø·¸¤Ê¤¤¤è¤¦¤Ç¤¹¤·¡¢¤É¤¦¤·¤¿¤éÎɤ¤¤«Ê¬¤«¤é¤Ê¤¯¤Ê¤ê¤Þ¤·¤¿¤Î¤Ç¡¢¥¢¥É¥Ð¥¤¥¹¤ò¤ª´ê¤¤¤¤¤¿¤·¤Þ¤¹¡£ - ¶ÛµÞÅÙ¡§Ä̾ïÅê¹Æ¼Ô¡§isampm¤µ¤óÅê¹Æ»þ´Ö¡§2020/06/13 10:19
²óÅú No.10365
-
ËÜʸ¡§
echo $sql;
¤Ç¡¢ÁȤßΩ¤Æ¤¿SQLʸ¤ò³Îǧ¤·¤Æ¤Ï¡©
ÌäÂê¤Ê¤¤SQL¤¬À¸À®¤µ¤ì¤Æ¤Þ¤¹¤«¡©
¢£
¼ÂºÝ¤Ë¡¢phpAdmin¤Ç¡¡¾åµ¤ÇÀ¸À®¤·¤¿SQL¤ò¼Â¹Ô¤·¤Æ¤ß¤ì¤Ð¡¢
¥¨¥é¡¼¤Î¸Ä½ê¤â¤Ï¤Ã¤¤ê¤¹¤ë¤«¤â¡£
¢£
¤¿¤È¤¨¤Ð¡¢
insert into meibo(id,namae,jyusyo) VALUES(20,'Yamada','Tokyo')
¤Î¤è¤¦¤ÊSQL¤Ë¤Ê¤ë¤È»×¤¦¡£
VALUES¤Î¤È¤³¤í¤Ç¡¢Ê¸»úÎó¤ÎÉôʬ¤Ï¡¢¡Ç¡Ç¤«¡É¡É¤Ç¤¯¤¯¤ë
- Åê¹Æ¼Ô¡§k-tan¤µ¤ó Åê¹Æ»þ´Ö¡§2020/06/13 11:23
¼ÁÌä¼Ô¤«¤é¤Î¥³¥á¥ó¥È
k-tan¤µ¤ó¡¢²óÅú¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤¹¡£
¡¡echo $sql¤Ç³Îǧ¤Ï¤¹¤°½ÐÍè¤Þ¤¹¤Î¤Ç¡¢¤ä¤Ã¤Æ¸«¤è¤¦¤«¤È»×¤¤¤Þ¤¹¡£phpAdmin¤ÎSQL¤Ç¤ä¤Ã¤Æ¸«¤ë¤Î¤â¤¤¤¤¤«¤â¤·¤ì¤Þ¤»¤ó¡£º£¤Þ¤Ç¤Ï°ìʸ¤·¤«¤ä¤Ã¤Æ¤Þ¤»¤ó¤¬¡¢Â¿Ê¬¤Ç¤¹¤¬¡¢Ê£¿ô¤Ç¤â¤ä¤ì¤ë¤È»×¤¦¤Î¤Ç¡¢ÊÑ¿ô¤ËÃͤò¥»¥Ã¥È¤·¤Æ¤ä¤Ã¤Æ¸«¤ë¤Î¤âÎɤ¤¤è¤¦¤Ë»×¤¤¤Þ¤¹¡£ÊÑ¿ô¤Î¥¿¥¤¥×¤È¤¤¤¦¤Î¤¬Ìµ¤¤¤Î¤Ç¡¢Ê¸»úÎó¤ÎÊÑ¿ô¤Ï¥¯¥ª¡¼¥È¤Ç°Ï¤á¤Ê¤¤¤È»×¤¦¤Î¤Ç¡¢¥¥ã¥¹¥È¤·¤Æ¤ä¤Ã¤Æ¸«¤Æ¤â´Ø·¸¤Ê¤¤¤è¤¦¤Ç¤¹¡£values¤ÇÀ°¿ô¤Èʸ»úÎó»ØÄꤹ¤ëÊýË¡¤Ç¤Ï½ÐÍè¤Æ¤Þ¤¹¡£Îã¤Ç½ñ¤¤¤Æ¤¯¤ì¤¿sql¤Î20¤ÎÉôʬ¤Ïprint¤Ç¤ÏÀ°¿ô¤Î¤è¤¦¤Ë¸«¤¨¤ë¤È¤³¤Ë$_POST¤òÂå¤ï¤ê¤ËÆþ¤ì¤ì¸«¤¿¤ó¤Ç¤¹¤¬¡¢¤É¤¦¤â¼«Ê¬¤Î¾ï¼±¤¬Ä̤¸¤Ê¤¤¤è¤¦¤Ç¤¹¡£
²óÅú No.10367
-
ËÜʸ¡§
Íפϡ¢
"INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
((int)$Meiboid, (string)$Simei, (string)$Ikajyusyo, (int)$Todouhukencode)" ...¡
¤ÎÉôʬ¤Ï¡¢¤Þ¤ºPHP¤Îʸ»úÎó¤È¤·¤Æɾ²Á¤µ¤ì¤Æ¡¢¤½¤Î·ë²Ì¤Îʸ»úÎ󤬡¢mySQL¤Î¼°¤È¤·¤ÆÅϤµ¤ì¤ë¤È¤¤¤¦¤³¤È¤òÍý²ò¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¤Í¡£
¤Ä¤Þ¤ê¡¢$Meiboid = 20 , $Simei = "Yamada Taro" , $Ikajyusyo = "²â¤¬´Ø1-1" , $Todouhukencode = "41" ¤Î¤È¤¤Ë¡¢$sql ¤Ï¡¢
INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
((int)20, (string)Yamada Taro, (string)²â¤¬´Ø1-1, (int)41)
¤È¤Ê¤Ã¤Æ¡¢
INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
((int)20, (string)'Yamada Taro', (string)'²â¤¬´Ø1-1', (int)41)
¤Ë¤Ï¤Ê¤é¤Ê¤¤¤Î¤Ç¡¢´üÂÔ¤·¤¿¤¤·ë²Ì¤¬Íߤ·¤¤¤Î¤Ê¤é¡¢ºÇ½é¤Î$sql ʸ¤Ï¡¢
"INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
((int)'$Meiboid', (string)'$Simei', (string)'$Ikajyusyo', (int)'$Todouhukencode')"
¤È½ñ¤«¤Ê¤¤¤È¤¤¤±¤Ê¤¤¡£
⤷¡¢¤³¤Î¾ì¹ç¤Ç¤â¡¢$Simei ¤Ê¤É¤Ë¡¢"'" ¤Î¤è¤¦¤ÊÆüì¤Êʸ»ú¤¬´Þ¤Þ¤ì¤ë²ÄǽÀ¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï(Î㤨¤Ð¡¢$Simei = "Peter's Papa" ¤Î¤è¤¦¤Ê¾ì¹ç)¡¢·ë²Ì¤Îʸ»úÎó¤Ï¡¢
INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
((int)20, (string)'Peter's Papa', (string)'²â¤¬´Ø1-1', (int)41)
¤È¤Ê¤Ã¤Æ¡¢SQLʸ¤È¤·¤Æ¤ÏÀµ¤·¤¯¤Ê¤¯¤Ê¤Ã¤Æ¥¨¥é¡¼¤Ë¤Ê¤ë¡£
(¤¤¤ï¤æ¤ë¡¢SQL injection¤¬²Äǽ¤Ê·Á¤Ë¤Ê¤Ã¤Æ´í¸±)
¤³¤ì¤òÈò¤±¤ë¤Ë¤Ï¡¢$dbh->query ¤Ç¤Ê¤¯¡¢$dbh->perpare ¤È $stmt->execute ¤ò»È¤Ã¤Æ¡¢
$sql = "INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
(?, ?, ?, ?)";
$stmt=$dbh->prepare( $sql );
$stmt->execute( array( (int)$Meiboid, (string)$Simei, (string)$Ikajyusyo, (int)$Todouhukencode )); ...¢
¤Î¤è¤¦¤Ë¤¹¤ë¤Î¤¬ÉáÄÌ¡£
# ¤³¤³¤Ç¡¢¡¤Î(int)¤ä¡¢(string)¤Ï¡¢mySQL¤Î·¿ÊÑ´¹¤Ê¤Î¤ËÂФ·¡¢¢¤Î(int)¤ä¡¢(string)¤Ï¡¢PHP¤Î·¿ÊÑ´¹¤Ç¤¢¤ë¤³¤È¤ËÃí°Õ¡£
- Åê¹Æ¼Ô¡§¥¸¥ç¥Ð¥ó¥Ë¤µ¤ó Åê¹Æ»þ´Ö¡§2020/06/13 13:30
¼ÁÌä¼Ô¤«¤é¤Î¥³¥á¥ó¥È
1¥¸¥ç¥Ð¥ó¥Ë¤µ¤ó¡¢²óÅú¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤¹¡£
¡¡¿¼¤¤ÆâÍƤǡ¢¾¯¤·Íý²ò¤Ç¤¤Þ¤»¤ó¤¬¡¢Æ¬¤ÎÊÒ¶ù¤Ç¤âÆþ¤ì¤Æ¤ª¤¤¿¤¤¤È»×¤¤¤Þ¤¹¡£º£²ó¤Îµ¿Ìä¤Ï¡¢Ê¸»úÎó¤¬"'"¤Ç³ç¤Ã¤Æ¤Ê¤¤¤³¤È¤¬¸¶°ø¤Ç¤·¤¿¡£Îɤ¯Ê¬¤«¤é¤Ê¤¤¤Ç¿Ê¤á¤Æ¤¤Þ¤·¤¿¤¬¡¢"¤È¡Ç¤Î°ã¤¤¤Ï¤É¤³¤Ë½ñ¤¤¤Æ¤¢¤ê¤Þ¤¹¤«¡©
²óÅú No.10369
-
ËÜʸ¡§
¤Ä¤Þ¤ê¡¢À¸¤Îʸ»úÎó¤È¤·¤Æ½èÍý¤µ¤»¤ë¤¿¤á¤Ë¤Ï¡¢²ò¼á¤µ¤ì¤Ê¤¤¤è¤¦¤Ë¥¯¥©¡¼¥Æ¡¼¥·¥ç¥ó¤Ç¤¯¤¯¤é¤Ê¤¤¤È¤¤¤±¤Ê¤¤¤ï¤±¤Ç¤¹¡£
¥·¥ó¥°¥ë¥¯¥©¡¼¥Æ¡¼¥·¥ç¥ó¤È¥À¥Ö¥ë¥¯¥©¡¼¥Æ¡¼¥·¥ç¥ó¤Î2¼ïÎà¤Ê¤¤¤È¡¢¤Þ¤º¡¢°ìÊý¤Îµ¹æ¤òʸ»úÎó¤Ë´Þ¤á¤¿¤¤¤È¤¤Ë¡¢¤¯¤¯¤ë¥¯¥©¡¼¥Æ¡¼¥·¥ç¥ó¤¬¤Ê¤¯¤Æº¤¤ê¤Þ¤¹¡£¤Û¤«¤Ë¤â¡¢¸À¸ì¤Ê¤É¤Ë¤â¤è¤ë¤â¤Î¤Î¡¢¿§¡¹¤ÈÍýͳ¤äºîË¡¤¬¤¢¤ë¤È»×¤¤¤Þ¤¹¤¬¡£
¤¢¤Ê¤¿¤Ï¤Þ¤º¡¢¡Ö¥¨¥¹¥±¡¼¥×¡×¤È¤¤¤¦³µÇ°¤òÍý²ò¤¹¤Ù¤¤Ê¤Î¤À¤í¤¦¤È»×¤¤¤Þ¤¹¡£
- Åê¹Æ¼Ô¡§ayaguchi¤µ¤ó Åê¹Æ»þ´Ö¡§2020/06/13 18:19
²óÅú No.10368
¤³¤Î²óÅú¤¬¥Ù¥¹¥È¥¢¥ó¥µ¡¼¤Ç¤¹
¤¿¤Ö¤ó¡¢
$sql = "INSERT INTO `isamstar2_wp1`.`meibo` (`id`, `namae`, `jyusyo`, `prefcode`) VALUES
($Meiboid, \"$Simei\", \"$Ikajyusyo\", $Todouhukencode)";
¤È½ñ¤´¹¤¨¤¿¤éÆ°¤¯¤ó¤¸¤ã¤Ê¤¤¤«¤Ê¤¡¡£
»ä¤Î²óÅú¤Ï¡¢¤³¤ì¤Ç½ªÎ»¡£
¼ÁÌä¼Ô¤«¤é¤Î¥³¥á¥ó¥È
k-tan¤µ¤ó¡¢²óÅú¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤¹¡£
¡¡¤¤¤í¤¤¤í»î¤·¤¿·ë²Ì¡¢Ê¸»úÎó¤Î¥Ç¡¼¥¿¤¬"'"¤Ç°Ï¤Þ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤¬Ê¬¤«¤ê¤Þ¤·¤¿¡£ÀèƬ¤È½ª¤ï¤ê¤Ë"'"¤òÉÕ¤±¤¿¤éÆ°¤¤Þ¤·¤¿¡£²óÅú¤ò»î¤·¤Æ¤Þ¤»¤ó¤¬¡¢¼ã¤·¤«¤·¤¿¤é¤½¤¦¤¤¤¦¤³¤È¤«¤â¤·¤ì¤Þ¤»¤ó