-1

このコードの私の目標は、ユーザーの後で適用セクションを作成することです。正確な投稿の ID を取得するための隠しボタンを作成しました。ID を取得していますが、バインドして実行すると、この警告が表示されます。いくつかチェックしました他の人々は私のものと同様の質問をしますが、彼らは私の正確な問題を解決していないようです. その特定のIDを持つ投稿の情報を取得するためにバインドする正確なものは何ですか?

関数は次のとおりです:

public function Index(){

    if(isset($_POST['submit'])){
        $id = $_POST['applylater_id'];// I got this from a button the user is to click
        // INSERT INTO MYSQL
        $this->query('INSERT INTO apply_later(id, title, body, link, user_id, user_name) SELECT id, title, body, link, user_id, user_name FROM shares WHERE id = :id');
        $this->bind(':title', 'title');
        $this->bind(':body', 'body');
        $this->bind(':link', 'link');
        $this->bind(':user_id', 1);
        $this->bind(':user_name', 'user_name');         
        $this->bind(':id', $id);
        $this->execute();

        //Verify
        if($this->lastInsertId()){
            //Redireect
            Messages::setMsg('Successfully Added to your apply Later section', 'successMsg'); 
            header( "refresh:2; url=http://localhost/phpsandbox/phptutorials/website2/shares/applylater" );

        }
    }
    //
    $this->query('SELECT * FROM shares ORDER by id desc ');
    $rows = $this->resultSet();
    return $rows;
}

//これは、上記で呼び出したバインド関数と実行関数です

public function query($query){
    $this->stmt = $this->dbh->prepare($query);
}


public function bind ($param, $value, $type =null) {
if(is_null($type)){
    switch(true) {
        case is_int($value):
            $type = PDO::PARAM_INT;
            break;
        case is_bool($value):
            $type = PDO::PARAM_BOOL;
            break;
        case is_null($value):
            $type = PDO::PARAM_NULL;
            break;
            default:
            $type = PDO::PARAM_STR;
    }

        }
    $this->stmt->bindValue($param, $value, $type);
}

public function execute(){
    return $this->stmt->execute();
}

これは私が使用するメインフォームですが、IDを取得できますが、画面に表示されません

<?php foreach ($viewmodel as $item) : ?>
    <div class="well">
        <div class="text-center">
            <img src="http://localhost/phpsandbox/phptutorials/website2/assets/image/job.png" class="img-circle" alt="Cinque Terre" width="50" height="50">

        <h3> <?php echo $item['title']; ?></h3>
        <small> Username: <?php echo $item['user_name']; ?></small>
        <br />
        <small><?php echo $item['create_date']; ?></small>
        </div>
        <hr />
        <p><?php echo $item['body']; ?></p>
        <br />
        <div class="text-center">
            <a href="<?php echo $item['link']; ?>" target="_blank"  class="btn btn-info">Apply Now</a>
            <br />

        </div>
        <hr />
        <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>" >

//送信をクリックすると、この正確な投稿のIDを取得し、データを別のテーブルに送信して、この正確なものを別のページに表示できるようにします。

                <input type="hidden" name="applylater_id" value="<?php echo $item['id']; ?>">
                <input class="btn btn-primary" type="submit" name="submit" value="Apply Later">
        </form>

これが私のテーブルです

    </div>[enter image description here][1]
4

1 に答える 1