Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:27:41+00:00 2026-06-08T12:27:41+00:00

in a php file that use this line of code to insert some text

  • 0

in a php file that use this line of code to insert some text in the table TABONE

mysql_query("INSERT INTO `TABONE` VALUES ('$q1', '$q2', '$q3',  '$q4',  '$q5')") ;

the code work fine because “we receive 5 variables and this table contain 5 columns“

but sometimes we receive 5 variables for a table that contain only 3 columns and in this case we just want to insert the first 3 variables (‘$q1’, ‘$q2’, ‘$q3’)in the 3 columns.

in this case

mysql_query("INSERT INTO `TABONE` VALUES ('$q1', '$q2', '$q3',  '$q4',  '$q5')") ; 

doesn’t work – How to correct this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:27:42+00:00Added an answer on June 8, 2026 at 12:27 pm

    As stated in the manual:

    • If you are not running in strict SQL mode, any column not explicitly given a value is set to its default (explicit or implicit) value. For example, if you specify a column list that does not name all the columns in the table, unnamed columns are set to their default values. Default value assignment is described in Section 11.5, “Data Type Default Values”. See also Section 1.8.6.2, “Constraints on Invalid Data”.

      If you want an INSERT statement to generate an error unless you explicitly specify values for all columns that do not have a default value, you should use strict mode. See Section 5.1.6, “Server SQL Modes”.

    • Use the keyword DEFAULT to set a column explicitly to its default value. This makes it easier to write INSERT statements that assign values to all but a few columns, because it enables you to avoid writing an incomplete VALUES list that does not include a value for each column in the table. Otherwise, you would have to write out the list of column names corresponding to each value in the VALUES list.

      You can also use DEFAULT(col_name) as a more general form that can be used in expressions to produce a given column’s default value.

    Therefore, you can:

    1. name the columns and omit those for which you want default values:

      INSERT INTO TABONE (colA, colB, colC) VALUES ('$q1', '$q2', '$q3')
      

      Or, if you prefer the SET syntax:

      INSERT INTO TABONE SET colA='$q1', colB='$q2', colC='$q3'
      
    2. explicitly set the other columns to their default values with the DEFAULT keyword:

      INSERT INTO TABONE VALUES ('$q1', '$q2', '$q3', DEFAULT, DEFAULT)
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a project, with various subdirs that make use of a functions.php file located
I use the PHP language for file upload and want to know that the
So I have a php file that retrieves some variables with the $_GET method
i have a table that display a record from the database. Using this php
I have this PHP function (using PHP 5.3) that I use to decrypt files,
I'm trying to use a MERGE INTO statement in my php file to update
I have a PHP file with a line that produces a warning in NetBeans.
I use php to create a file that can be donwloaded when pressing a
I'm making a php file that will run an event after five minutes have
I have a PHP file that contains a large array (about 90KB). I'm considering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.