简体   繁体   English

在MySQL数据库中使用事件保存日期

[英]Saving date with events in mysql database

I'm trying to insert dates with events in the database, first I populate table with dates and textarea, as seen in the image,. 我试图在数据库中插入带有事件的日期,首先,我在表中填充了日期和文本区域,如图中所示。 After filling the textarea, you will hit submit to save the events in the database, only the textarea with value is suppose to be stored but what is happening, all the dates is saving even without events input. 填充文本区域后,您将单击“提交”以将事件保存在数据库中,假定只存储具有值的文本区域,但是发生了什么,即使没有输入事件也保存了所有日期。 在此处输入图片说明

Below is the codes for saving in the database. 以下是保存在数据库中的代码。

 if(isset($_POST['submit_calendar']))
        {
                $memo = $_POST['memo'];
                $cMonth = $_POST['cal_month'];
                $cYear = $_POST['cal_year'];

                $timestamp = mktime(0,0,0,$cMonth,1,$cYear);
                $maxday = date("t",$timestamp);
                $thismonth = getdate ($timestamp);
                $startday = $thismonth['wday'];

                for ($i=0; $i<$maxday+$startday; $i++) 
                {
                    if($i < $startday) continue;

                    if($memo == NULL)
                    {
                        $i++;
                        continue;
                    }
                    else    
                    {
                        $date = $cYear."/".$cMonth."/".($i-$startday+1);
                        $event = $memo[$i-$startday];

                        $query = "INSERT INTO calendar SET cal_date='$date', cal_event='$event'";
                        $q = mysql_query($query);
                    }
                }   
        }

Try 尝试

if(strlen(trim($event))>0){
  $query = "INSERT INTO calendar SET cal_date='$date', cal_event='$event'";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM