Posting to a field in a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jbradly
    New Member
    • Mar 2008
    • 13

    Posting to a field in a table

    I am pretty new at php but I think I have an understanding of its logic.
    I have a table in a database called Announcements. One of the fields is called Principal_Messa ge. The other fields in the table are Important_Event s and Daily_Announcem ents. I just want to post data to Principal_Messa ge using a form and I want to post to the other fields using other forms. I have created the form and a review page to review the data for the field before it is posted. I have created a processing page to actually post the data to the table. Its code is
    [PHP]
    $Message = $_POST['princmsg'];
    $db = mysqli_connect( "localhost" , "", "", "db-jvadmin");

    $sql = "INSERT INTO Announcements (Principal_Mess age) VALUES ('$Message')";

    mysqli_query($d b, $sql) or die(mysqli_erro r($db));
    [/PHP]
    The problem I have is in the processing page, I get the message:
    Field 'Important_Even ts' doesn't have a default value.

    Right now the table is empty and I am trying to test my pages to see if they work. Does anybody have any suggestions?
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    That's not your php code that's the problem, it's your database coding. Have a look here to see how to set defaults or have DEFAULT NULL (which is what I think you want). If there is nothing in the tables, just drop that one and when you make each field, include DEFAULT NULL after where you put what type of field it is.

    I will ahve a look, just not sure what the command is to change the default after the table has been created. *Also, make sure you ahve not put NOT NULL in the table creation, because this means that it needs to have something.

    Hope I made sense!

    Comment

    • jbradly
      New Member
      • Mar 2008
      • 13

      #3
      Thanks, that does make sense. I will check it out.

      Comment

      Working...