将数据插入mysql

时间:2019-02-26 05:44:17

标签: php mysql

无法处理此请求

<?php
    error_reporting( ~E_NOTICE ); // avoid notice
    require_once 'dbconfig.php';
    if(isset($_POST['btnsave']))
    {
        $title = $_POST['title'];// user name
        $date = $_POST['date'];// user email
        $shorttext = $_POST['short_text'];
        if(empty($title)){
            $errMSG = "Please Enter Title.";
        }
        else if(empty($date)){
            $errMSG = "Please Enter Date.";
        }
        else if(empty($shorttext)){
            $errMSG = "Please Enter Short Text.";
        }
        // if no error occured, continue ....
        if(!isset($errMSG))
        {
            $stmt = $DB_con->prepare('INSERT INTO newsevents(title,date,shorttext) VALUES(:title, :date, :shorttext)');
            $stmt->bindParam(':title',$title);
            $stmt->bindParam(':date',$date);
            $stmt->bindParam(':shorttext',$shorttext);
            if($stmt->execute())
            {
                $successMSG = "new record succesfully inserted ...";
                /*header("refresh:5;index.php"); // redirects image view page after 5 seconds.*/
            }
            else
            {
                $errMSG = "error while inserting....";
            }
        }
    }

0 个答案:

没有答案