function insert_movies($title, $url, $img, $movie_type, $itemCaption)
{
    //db接続を確立
    $insert_db = connect2MySQL();
    //DBに全項目のある1レコードを登録するSQL
    $insert_sql = "INSERT INTO movies(FilmTitle,FilmUrl,ImageUrl,movie_type,itemCaption)" . "VALUES(:FilmTitle,:FilmUrl,:ImageUrl,:movie_type,:itemCaption)";
    // //現在時をdatetime型で取得
    // $datetime =new DateTime();
    // $date = $datetime->format('Y-m-d H:i:s');
    //クエリとして用意
    $insert_query = $insert_db->prepare($insert_sql);
    //SQL文にセッションから受け取った値&現在時をバインド
    $insert_query->bindValue(':FilmTitle', $title);
    $insert_query->bindValue(':FilmUrl', $url);
    $insert_query->bindValue(':ImageUrl', $img);
    $insert_query->bindValue(':movie_type', $movie_type);
    $insert_query->bindValue(':itemCaption', $itemCaption);
    //SQLを実行
    try {
        $insert_query->execute();
    } catch (PDOException $e) {
        // echo $e->getMessage();
        //接続オブジェクトを初期化することでDB接続を切断
        $insert_db = null;
        echo $e->getMessage();
        return $e->getMessage();
    }
    $insert_db = null;
    return null;
}
Example #2
0
function insertprof($name, $birthday, $type, $tell, $comment)
{
    try {
        //DBに全項目のある1レコードを登録するSQL
        // $insert_sql = "INSERT INTO user_t(name,birthday,tell,type,comment,newDate)"
        //         . "VALUES(:name,:birthday,:tell,:type,:comment,:newDate)";
        $insert_sql = "INSERT INTO user_t(name,birthday,tell,type,comment,newDate)" . "VALUES(:name,:birthday,:tell,:type,:comment,:newDate)";
        //クエリとして用意
        $insert_db = connect2MySQL();
        $insert_query = $insert_db->prepare($insert_sql);
        //SQL文にセッションから受け取った値&現在時をバインド
        $insert_query->bindValue(':name', $name);
        $insert_query->bindValue(':birthday', $birthday);
        $insert_query->bindValue(':tell', $tell);
        $insert_query->bindValue(':type', $type);
        // $insert_query->bindValue(':type','あ');
        $insert_query->bindValue(':comment', $comment);
        // $insert_query->bindValue(':newDate',time());
        $insert_query->bindValue(':newDate', date("y-m-d H:i:s"));
        //SQLを実行
        $insert_query->execute();
        // if(!$insert_query->execute()){
        //     echo "エラー";
        // }
        //接続オブジェクトを初期化することでDB接続を切断
        $insert_db = null;
    } catch (PDOException $e) {
        echo "データの挿入に失敗しました:" . $e->getMessage();
    }
}
function login($name)
{
    //db接続を確立
    $login_db = connect2MySQL();
    $login_sql = "select userID, name, password from user_t where name = :name";
    //クエリとして用意
    $login_query = $login_db->prepare($login_sql);
    $login_query->bindValue(':name', $name);
    //SQLを実行
    try {
        $login_query->execute();
    } catch (PDOException $e) {
        $login_query = null;
        return $e->getMessage();
    }
    $result = $login_query->fetchAll(PDO::FETCH_ASSOC);
    return $result;
}
function delete_profile($id)
{
    //db接続を確立
    $delete_db = connect2MySQL();
    $delete_sql = "DELEtE * FROM user_t WHERE userID=:id";
    //クエリとして用意
    $delete_query = $delete_db->prepare($delete_sql);
    $delete_query->bindValue(':id', $id);
    //SQLを実行
    try {
        $delete_query->execute();
    } catch (PDOException $e) {
        $delete_query = null;
        return $e->getMessage();
    }
    return null;
}
<head>
<meta charset="UTF-8">
      <title>登録結果画面</title>
</head>
<body>

    <?php 
// エラーを表示させる
ini_set('display_errors', 1);
// session_start();
$name = $_SESSION['name'];
$birthday = $_SESSION['birthday'];
$type = $_SESSION['type'];
$tell = $_SESSION['tell'];
$comment = $_SESSION['comment'];
$insert_db = connect2MySQL();
insert_data($insert_db, $name, $birthday, $tell, $type, $comment, $datetime);
?>


    <h1>登録結果画面</h1><br>
    名前:<?php 
echo $name;
?>
<br>
    生年月日:<?php 
echo $birthday;
?>
<br>
    種別:<?php 
echo $type;
Example #6
0
function update_profile($id, $name, $birthday, $type, $tell, $comment)
{
    //db接続を確立
    $update_db = connect2MySQL();
    //DBに全項目のある1レコードをアップデートするSQL
    $update_sql = "UPDATE user_t SET name=:name,birthday=:birthday,tell=:tell,\n  type=:type,comment=:comment,newDate=:newDate WHERE userID=:id";
    //現在時をdatetime型で取得
    $datetime = new DateTime();
    $date = $datetime->format('Y-m-d H:i:s');
    //クエリとして用意
    $update_query = $update_db->prepare($update_sql);
    //SQL文にセッションから受け取った値&現在時をバインド
    $update_query->bindValue(':id', $id);
    $update_query->bindValue(':name', $name);
    $update_query->bindValue(':birthday', $birthday);
    $update_query->bindValue(':tell', $tell);
    $update_query->bindValue(':type', $type);
    $update_query->bindValue(':comment', $comment);
    $update_query->bindValue(':newDate', $date);
    //SQLを実行
    try {
        $update_query->execute();
    } catch (PDOException $e) {
        //接続オブジェクトを初期化することでDB接続を切断
        $update_db = null;
        return $e->getMessage();
    }
    $update_db = null;
    return null;
}
Example #7
0
    <?php 
session_start();
$name = $_SESSION['name'];
$birthday = $_SESSION['birthday'];
$type = $_SESSION['type'];
$tell = $_SESSION['tell'];
$comment = $_SESSION['comment'];
//DBに全項目のある1レコードを登録するSQL
$insert_sql = "INSERT INTO user_t(name,birthday,tell,type,comment,newDate)" . "VALUES(:name,:birthday,:tell,:type,:comment,:newDate)";
//課題5:直接リンクしてアクセスした時のエラー処理を追加
if (empty($_POST['link'])) {
    echo 'アクセスエラーです。' . "<br>";
} else {
    //課題8:データベースアクセス系の処理をdbaccesUtil.phpから取得
    connect2MySQL($insert_sql, $name, $birthday, $tell, $type, $comment);
}
//課題5:直接リンクしてアクセスした時に表示されない処理を追加
if (isset($_POST['link'])) {
    ?>
      <h1>登録結果画面</h1><br>
      名前:<?php 
    echo $name;
    ?>
<br>
      生年月日:<?php 
    echo $birthday;
    ?>
<br>
      種別:<?php 
    echo ex_typenum($type);
Example #8
0
function update_profile($name, $birthday, $type, $tell, $comment, $userID)
{
    //db接続を確立
    $update_db = connect2MySQL();
    // [修正] デフォルトは"DELETE * FROM user_t WHERE userID=:id"。*が不要の構文エラーが出たため、削除。
    $update_sql = "UPDATE user_t SET\n\t\t\t\t\tname=:name, birthday = :birthday, tell = :tell, type =  :type, comment = :comment, newDate = :newDate\n\t\t\t\t\tWHERE userID=:id";
    //現在時をdatetime型で取得
    $datetime = new DateTime();
    $date = $datetime->format('Y-m-d H:i:s');
    //クエリとして用意
    $update_query = $update_db->prepare($update_sql);
    //SQL文にセッションから受け取った値&現在時をバインド
    $update_query->bindValue(':id', $userID);
    $update_query->bindValue(':name', $name);
    $update_query->bindValue(':birthday', $birthday);
    $update_query->bindValue(':tell', $tell);
    $update_query->bindValue(':type', $type);
    $update_query->bindValue(':comment', $comment);
    $update_query->bindValue(':newDate', $date);
    //SQLを実行
    try {
        $update_query->execute();
    } catch (PDOException $e) {
        $update_query = null;
        return $e->getMessage();
    }
    return null;
}
Example #9
0
</head>
<body>

<?php 
//回答5.POSTを用いたページ遷移のエラー表示
if (isset($_POST['access']) != 't') {
    echo '不正なアクセスです' . "<br/>";
    echo return_top();
} else {
    session_start();
    $name = $_SESSION['name'];
    $birthday = $_SESSION['birthday'];
    $tell = $_SESSION['tell'];
    $type = $_SESSION['type'];
    $comment = $_SESSION['comment'];
    if ($_SESSION['type'] == 'エンジニア') {
        $type_num = 1;
    } elseif ($_SESSION['type'] == '営業') {
        $type_num = 2;
    } elseif ($_SESSION['type'] == 'その他') {
        $type_num = 3;
    }
    //種別を数字に変換してDB上へ管理する処理
    //db接続を確立
    $insert_db = connect2MySQL($name, $birthday, $tell, $type_num, $comment);
    echo '<h1>登録結果画面</h1><br>' . '名前:' . $name . '<br>' . '生年月日:' . $birthday . '<br>' . '種別:' . $type . '<br>' . '電話番号:' . $tell . '<br>' . '自己紹介:' . $comment . '<br>' . '以上の内容で登録しました。<br>';
    echo return_top();
}
?>
</body>
</html>
Example #10
0
function update_profile($id, $name, $birthday, $type, $tell, $comment)
{
    $update_db = connect2MySQL();
    $update_sql = "UPDATE user_t SET name=:name,birthday=:birthday,type=:type,tell=:tell,comment=:comment,newDate=:newDate WHERE userID =:id";
    //現在時をdatetime型で取得
    $datetime = new DateTime();
    $date = $datetime->format('Y-m-d H:i:s');
    //クエリとして用意
    $update_query = $update_db->prepare($update_sql);
    $update_query->bindValue(':id', $id);
    $update_query->bindValue(':name', $name);
    $update_query->bindValue(':birthday', $birthday);
    $update_query->bindValue(':type', $type);
    $update_query->bindValue(':tell', $tell);
    $update_query->bindValue(':comment', $comment);
    $update_query->bindValue(':newDate', $date);
    //SQLを実行
    try {
        $update_query->execute();
    } catch (PDOException $e) {
        $update_query = null;
        return $e->getMessage();
    }
    //UPDATE用の関数
}
function update_profile($id, $name, $birthday, $type, $tell, $comment)
{
    $update_db = connect2MySQL();
    $update_sql = "UPDATE user_t SET\r\n                (name,birthday,type,tell,comment) =\r\n                ( {$name},{$birthday},{$type},{$tell},{$comment},)\r\n                WHERE userID ={$id}";
    //クエリとして用意
    $update_query = $update_db->prepare($update_sql);
    //SQLを実行
    try {
        $update_query->execute();
    } catch (PDOException $e) {
        //接続オブジェクトを初期化することでDB接続を切断
        $update_db = null;
        return $e->getMessage();
    }
    $update_db = null;
    return null;
}
function update_profile($userID, $name, $birthday, $type, $tell, $comment)
{
    //db接続を確立
    $update_db = connect2MySQL();
    //現在時をdatetime型で取得
    $datetime = new DateTime();
    $date = $datetime->format('Y-m-d H:i:s');
    $update_sql = "update user_t set name = :name, birthday = :birthday, type = :type, tell = :tell, comment = :comment, newDate =:newDate where userID = :userID;";
    //クエリとして用意
    $update_query = $update_db->prepare($update_sql);
    //SQL文にセッションから受け取った値&現在時をバインド
    $update_query->bindValue(':name', $name);
    $update_query->bindValue(':birthday', $birthday);
    $update_query->bindValue(':tell', $tell);
    $update_query->bindValue(':type', $type);
    $update_query->bindValue(':comment', $comment);
    $update_query->bindValue(':newDate', $date);
    $update_query->bindValue(':userID', $userID);
    //SQLを実行
    try {
        $update_query->execute();
    } catch (PDOException $e) {
        //接続オブジェクトを初期化することでDB接続を切断
        $update_db = null;
        return $e->getMessage();
    }
    $update_db = null;
    return null;
}