mysql / php插入查询问题

时间:2017-02-10 20:31:37

标签: php mysql

我有以下课程方法

public function index()
    {   
        $username = '';
        $email = '';
        $text = '';
        $picture = '';

        if (isset($_POST['submit']))
        {
            $username = $_POST['username'];
            $email = $_POST['email'];
            $text = $_POST['text'];
            $picture = $_POST['picture'];
            Task::create($username, $email, $text, $picture);
        }

        require_once(ROOT.'/views/site/index.php');
    }

我的表单发送值,我使用var_dump($_POST['username'])

进行了检查

这里是create()方法

public static function create($username, $email, $text, $picture='1', $check_token=false)
    {
        $db = Db::connect();
        $query = 'INSERT INTO tasks (username, email, text, picture, check_token)
                 VALUES (:username, :email, :text, :picture, :check_token)';

        $result = $db->prepare($query);
        $result->bindParam(':username', $username, PDO::PARAM_STR);
        $result->bindParam(':email', $email, PDO::PARAM_STR);
        $result->bindParam(':text', $text, PDO::PARAM_STR);
        $result->bindParam(':picture', $picture, PDO::PARAM_STR);
        $result->bindParam(':check_token', $check_token, PDO::PARAM_STR);

        $result->execute();
    }

我的数据库连接正确导致我的身份验证系统正常工作。但是这个查询没有插入任何东西。我的代码有什么问题? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

当是关键字时,您必须转义字段名称。所以你必须像这样放回fiel dname文本周围的刻度。

<section class="section-skills">
  <div class="item pri"></div>
  <div class="item sec">
    <div class="skills-box">
      <h2>WE ARE GOOD AT</h2>
      <p class="sub-text">Morbi tempor elit leo, eget mattis massa porta ac</p>
      <div class="skillbar clearfix " data-percent="90%">
        <div class="skillbar-title" style="background: #d35400;"><span>HTML5</span> 
        </div>
        <div class="skillbar-bar" style="background: #e67e22;"></div>
        <div class="skill-bar-percent">90%</div>
      </div>
      <!-- End Skill Bar -->
      <div class="skillbar clearfix " data-percent="85%">
        <div class="skillbar-title" style="background: #2980b9;"><span>CSS3</span>
        </div>
        <div class="skillbar-bar" style="background: #3498db;"></div>
        <div class="skill-bar-percent">85%</div>
      </div>
      <!-- End Skill Bar -->
      <div class="skillbar clearfix " data-percent="60%">
        <div class="skillbar-title" style="background: #2c3e50;"><span>jQuery</span>
        </div>
        <div class="skillbar-bar" style="background: #2c3e50;"></div>
        <div class="skill-bar-percent">60%</div>
      </div>
      <!-- End Skill Bar -->
      <div class="skillbar clearfix " data-percent="75%">
        <div class="skillbar-title" style="background: #46465e;"><span>PHP</span>
        </div>
        <div class="skillbar-bar" style="background: #5a68a5;"></div>
        <div class="skill-bar-percent">75%</div>
      </div>
      <!-- End Skill Bar -->
    </div>
  </div>
</section>