form action="data.php" method="post"> input type="text" name="select" /> input type="text" name="customer" /> input type="tel" name="tel" /> input type="text" name="address" /> input type="text" name="content" /> input type="submit" value="登録" /> /form>
$db_user="root"; $db_pass=""; $db_host="localhost"; $db_name="test"; $db_type="mysql"; $dsn= "$db_type:host=$db_host; dbname=$db_name; charset=utf8;"; try{ $pdo=new PDO($dsn, $db_user,$db_pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); }catch(PDOException $Exception){ die('エラー' .$Exception->getMessage()); } try{ $pdo->beginTransaction(); $sql ="INSERT INTO shop(tableSelect, name, tel, address, content, created) VALUES( :select, :customer, :tel, :address, :content, now())"; $stmh = $pdo->prepare($sql); $stmh->bindValue(':select', $_POST['select'], PDO::PARAM_STR); $stmh->bindValue(':customer', $_POST['customer'], PDO::PARAM_INT); $stmh->bindValue(':tel', $_POST['tel'], PDO::PARAM_INT); $stmh->bindValue(':address', $_POST['address'], PDO::PARAM_INT); $stmh->bindValue(':content', $_POST['content'], PDO::PARAM_STR); $stmh->execute(); $pdo->commit(); print "データを".$stmh->rowCount()."件挿入しましたbr />"; }catch(PDOException $Exception){ $pdo->rollback(); print "エラー:" .$Exception->getMessage(); }