简体   繁体   中英

details not storing into database

I recently upgraded my server and made a smooth transition, however I get a "MySQL Erorr" and I pinned down what exactly is not functioning correctly.

This code:

        $date = date("M jS");
        $articleTime = date("g:iA T");
        $articleTime = str_replace('EDT', 'EST', $articleTime);
        $ip = getenv("REMOTE_ADDR");        
        $insertYo = "INSERT INTO activity ( date, articleTime, action, icon, ip) VALUES ('$date', '$articleTime', '<strong><a href=\"/articles\">\Archives</a></strong> viewed on $date @', 'fa-archive', '$ip')";          
        mysql_query($insertYo) or die('MySQL Error.');

It isn't inserting correctly. How my database design is setup for "activity" is:

在此处输入图片说明

Database Design

Am I doing something wrong here? I believe it could have something to do with my database aswell, but other parts of the layout do work without this code on that page.

Your data table has seven columns that are non-nullable and do not have a default field value, but your INSERT statement only specifies five columns. You can't do that because the database needs to know what to put in the other two columns. Either add those columns to your INSERT statement, modify the table to make those columns nullable, or provide default values for those columns.

Which solution you use depends on the business needs of the application. For example, the columns that you need to handle are articleid and articleTitle. Does it make sense within the context of your application for an Activity to not be associated with any specific Article ID? If it does, then that column should be made nullable.

As an easy-to-understand real world analogy, an Employee normally must have an EmployeeId, but they do not necessarily have to have a HeadquartersDeskNumber. Maybe they are a roving salesperson with a home office.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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