$id = isset($_POST['id'])? $_POST['id']: null;
$statement = $com->prepare("SELECT * FROM 'posting' WHERE id = :id");
$statement->bindValue(':id',$id,PDO::PARAM_STR);
$target_data = $statement->fetch(PDO::FETCH_OBJ);
if($target_data) $target_pass = $target_data->password;
elseif(isset($_POST['edit']) === true)
$comment = $_POST['comment'];
$mail_address = $_POST['mail_address'];
$password = $_POST['password'];
if($password === $target_pass)
$statement = $com->prepare("UPDATE 'posting' SET name=:name,comment=:comment,mail_address=:mail_address WHERE id = :id");
$statement->bindValue(':name',$name,PDO::PARAM_STR);
$statement->bindValue(':comment',$comment,PDO::PARAM_STR);
$statement->bindValue(':mail_address',$mail_address,PDO::PARAM_STR);
$statement->bindValue(':id',$id,PDO::PARAM_STR);
$success_msg['edit_result'] = '更新に成功しました。';
$error_msgs['not_match_edit_pass'] = 'パスワードが正しくありません。';
header("Location: http://127.0.0.1/index.php");
elseif(isset($_POST['delete']) === true)
$password = $_POST['password'];
if($password === $target_pass)
$statement = $com->prepare("DELETE FROM 'posting' WHERE id = :id");
$statement->bindValue(':id',$id,PDO::PARAM_STR);
$success_msg['delete_result'] = '削除に成功しました。';
$error_msgs['not_match_delete_pass'] = 'パスワードが正しくありません。';
header("Location: http://127.0.0.1/index.php");
if(isset($_POST['delete']) !== true)
setcookie('posted_name',$name,time() + 60 * 60 * 24);
setcookie('posted_comment',$comment,time() + 5);
setcookie('posted_mail_address',$mail_address,time() + 60 * 60 * 24);
$_SESSION['success_msg'] = $success_msg;
$_SESSION['error_msgs'] = $error_msgs;