問題ないコードだと思うのですが、class Dataのif文のところで予期しないエラーが出てしまいます。
原因が全く分かりません。
<?php class PdoData{ private $db= "mysql:dbname=test;host=0fe4a882d268"; private $user="test"; private $pw="test"; function __construct(){ return new PDO($this->db,$this->user,$this->pw); } } class Data extends PdoData { private $pdo; function __construct(){ $this->pdo = parent::__construct(); } if($_SERVER['REQUEST_METHOD'] === "POST"){ $action=filter_input(INPUT_POST,"action"); switch($action){ case "add": $this->add(); break; } exit; } public function add(){ $title=filter_input(INPUT_POST,"title"); $comment=filter_input(INPUT_POST,"comment"); $stmt=$this->pdo->prepare("INSERT INTO memo(title,comment) VALUES(:title,:comment)"); $stmt->bindValue("title",$title); $stmt->bindValue("comment",$comment); $stmt->execute(); } } ?> コード
原因はエラーには書いてあるのでは
エラーは読まれたのでしょうか。
というか、まずエラーをコピペしてください(ヘルプ参照)
https://teratail.com/help/question-tips#questionTips34
回答2件
あなたの回答
tips
プレビュー