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 7857043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:54:28+00:00 2026-06-02T20:54:28+00:00

I have a problem when trying to insert a new record into a database.

  • 0

I have a problem when trying to insert a new record into a database. The problem I think is with the bit field. When I assign the value True i get this error:

Failed: Array ( [0] => Array ( [0] => 22018 [SQLSTATE] => 22018 [1] 
=> 245 [code] => 245 [2] => [Microsoft][SQL Server Native Client 10.0]
[SQL Server]Conversion failed when converting the varchar value ' 1 ' 
to data type bit. [message] => [Microsoft][SQL Server Native Client 10.0]
[SQL Server]Conversion failed when converting the varchar value ' 1 ' to 
data type bit. ) )

but if i change it to false it works. I will show some of my code. I have cut out most of it as i have narrowed it down to this variable:

$active = True;

here is my insert query.

$sqlInsert = "INSERT INTO customers(
                customerID,
                registeredDate,
                givenName,
                familyName,
                email,
                password,
                phone,
                mobile,
                property,
                street,
                locality,
                town,
                area,
                postalCode,
                active
            ) 
            VALUES(" .
                $newUser . "," .
                $date . ", ' " .
                $given . " ', ' " .
                $family . " ', ' " .
                $email . " ', ' " .
                $pwd . " ', ' " .
                $phone . " ', ' " .
                $mob . " ', ' " .
                $property . " ', ' " .
                $street . " ', ' " .
                $locality . " ' , ' " .
                $town . " ', ' " .
                $area . " ', ' " .
                $postalcode . " ', ' " .
                $active . " ')";

$stmtInsert = sqlsrv_query($conn, $sqlInsert);
  • 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-02T20:54:30+00:00Added an answer on June 2, 2026 at 8:54 pm

    I assume that the active field is of bit data type.

    You don’t use any quotation marks around the value being passed for the active field like what you do for customerid field.

    Also, I think you have to convert the value true / false to 1 / 0.

    Modified code: Noticed that the single quotes surrounding " . $active . " have been removed.

    $sqlInsert = "INSERT INTO customers(customerID, registeredDate, givenName,
                    familyName,  email, password, 
                    phone, mobile, property, 
                    street, locality, town,  
                    area, postalCode, active) 
                  VALUES(" . $newUser . "," . $date . ", ' " . $given . " ', 
                  ' " . $family . " ', ' " . $email . " ', ' " . $pwd . " ', 
                  ' " . $phone . " ', ' " . $mob . " ', ' " . $property . " ', 
                  ' " . $street . " ', ' " . $locality . " ' , ' " . $town . " ', 
                  ' " . $area . " ', ' " . $postalcode . " ', " . $active . ")";
    $stmtInsert = sqlsrv_query($conn, $sqlInsert);
    

    I am not sure why it worked with False value. I would suggest you to find out how the INSERT statement evaluates to after setting all the values. Instead of executing the statement, print the INSERT statement to screen/page and run it manually in the SQL Server Management Studio against the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trying to insert a record into the database (MySQL), using Entity Class
I am relatively new to Perl.I have been trying to insert data to database
I'm trying to insert new records into a SQL CE 4 database with LINQPad
I have a problem using the MySQLdb library. I'm trying to insert values into
I'm new to Obj-C, and I have a little problem here. I'm trying insert
I am trying to set an identity field's value before inserting the new record
Gday All, I have a baffling problem whilst trying to insert some chinese characters
Hey all, i have a problem with trying to get 2 forms to close
I have a problem when trying to insert certain characters through query with parameters.
I have three classes that pose a problem when trying to add a new

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.