通过php

时间:2017-08-16 05:58:26

标签: php mysqli

所以我通过日期时间jquery插件输入值,现在我通过mysqli php扩展插入我的数据库中的值。 但问题是它没有插入。它总是进入其他条件。我在scheduler.php页面中有我的表单,我从那里发送值到allforms.php我在那里调用类调度器的add方法,它位于user.php页面

allforms.php页面

    $operation = $_POST['operation'];
        if($operation == 'add'){
                $request = getSchedule();
                $scheduler = new Scheduler($request['title'],$request['urgency'],$request['meeting'],$request['minfo'],$request['snooze'],$request['textbox'],$request['datetime']);
                $result = $scheduler->add();
                echo $result;
        }   
        function getSchedule(){
            $request = [];
            $request['title'] = isset($_POST['title']);
            $request['urgency'] = isset($_POST['urgency'])?$_POST['urgency']:'';
            $request['meeting'] = isset($_POST['meeting'])?$_POST['meeting']:'';
            $request['minfo'] = isset($_POST['minfo'])?$_POST['minfo']:'';
            $request['snooze'] = isset($_POST['snooze'])?$_POST['snooze']:'';
            $request['textbox'] = isset($_POST['textbox'])?$_POST['textbox']:'';

            $request['datetime'] = isset($_POST['datetime'])?strtotime($_POST['datetime']):'';
            $request['datetime'] = date("Y-m-d",$request['datetime']);
            return $request;
        }

scheduler.php Page

class Scheduler {
    public $title;
    public $urgency;
    public $meeting;
    public $minfo;
    public $snooze;
    public $textbox;
    public $datetime;
    public function __construct($title,$urgency,$meeting,$minfo,$snooze,$textbox,$datetime){
            $this->title =$title;
            $this->urgency = $urgency;
            $this->meeting = $meeting;
            $this->minfo =$minfo;
            $this->snooze = $snooze;
            $this->textbox = $textbox;
            $this->datetime = $datetime;
            $connection = new Connection();
            $this->connect = $connection->connect();
    }
    public function add(){
        $sql = "INSERT INTO 
                    Meeting (title, urgency, meeting, minfo, snooze, textbox, datetime) 
                    VALUES ('{$this->title}', '{$this->urgency}', '{$this->meeting}', '{$this->minfo}','{$this->snooze}','{$this->textbox}','{$this->datetime}')";
        $result = $this->connect->query($sql);
        if($result)
            {
                return  $this->title ." has been registered ";
            }else {
                return  "Some error occured and we couldn't add the event";
            }
        }

    }

scheduler.php Page

 <form class="form-group" method="POST" action="allforms.php" >
            <div>
                <label><b>Title</b></label>
                <input type="text" placeholder="Enter your title here" name="title" >
            </div>
              <div>
                <label><b>Urgency Level</b></label>
                <select name="urgency" class="textbox" >
                  <option value="Low">Low</option>
                  <option value="Normal">Normal</option>
                  <option value="Critical">Critical</option>
                </select>
            </div>
            <div>
                <label><b>Meeting Type</b></label>
                <select name="meeting" class="textbox">
                  <option value="Telephonic">Telephonic</option>
                  <option value="Offline">Offline</option>
                  <option value="Online">Online</option>
                </select>
            </div>
            <div>
                <label><b>Meeting Info</b></label>
                <input type="text" name="minfo" placeholder="Enter location name , number or skype id ,etc.">
            </div>
            <div>
                <label><b>Snooze</b></label>
                <input type="number" placeholder="Enter Snooze time in minutes" name="snooze" class="textbox">
            </div>
            <div>
                <label><b>Description</b></label>
                <textarea name="textbox" class="textbox"></textarea>
            </div>
            <div class="form-group">
                    <label><b>Date/Time of the meeting</b></label>
                    <input type='text' id="datetimepickr" class="form-control" name="datetime">
            </div>
            <input type="hidden" name="operation" value="add">
            <button type="submit" name="add">Submit</button>
            </form>

1 个答案:

答案 0 :(得分:0)

更改日期时间格式,

  function getSchedule(){
            $request = [];
            $request['title'] = isset($_POST['title']);
            $request['urgency'] = isset($_POST['urgency'])?$_POST['urgency']:'';
            $request['meeting'] = isset($_POST['meeting'])?$_POST['meeting']:'';
            $request['minfo'] = isset($_POST['minfo'])?$_POST['minfo']:'';
            $request['snooze'] = isset($_POST['snooze'])?$_POST['snooze']:'';
            $request['textbox'] = isset($_POST['textbox'])?$_POST['textbox']:'';

            $request['datetime'] = isset($_POST['datetime'])?strtotime($_POST['datetime']):'';
            $request['datetime'] = date("Y-m-d H:i",$request['datetime']);
            return $request;
        }