1

我将使用这个值:

$HEA_LivingWill  = $_POST['HEA_LivingWill'] == 'on'  ? true : false;

更新bitsql server 表中的字段。

请注意上面的代码是php。

我想$_POST['HEA_LivingWill']can 的值是'on', null, 或者是 'on' 的反义词

bit从 php 中的常规变量处理 sql server 字段的正确方法是什么?

请注意,当我做一个像update mytable set my field =$HEA_LivingWill查询这样的 sql 语句时,甚至没有通过。它没有给我一条错误消息,我知道查询没有执行,因为我使用 sql server profiler/

请注意,我也尝试过$HEA_LivingWill = $_POST['HEA_LivingWill'] == 'on' ? 1:0;收到相同的结果。

如果您对它感兴趣,这里是从 php 运行的插入语句:

 $create_info = mssql_query("INSERT INTO 
 Health 
 (RES_ID, HEA_LastUser, HEA_DateStamp, HEA_Vision, HEA_Hearing, HEA_Mobility, HEA_Falls, HEA_Food, HEA_FoodPref, HEA_FoodDetails, HEA_Insect, HEA_InsectDetails, HEA_Driver, HEA_Make, HEA_Model, HEA_Year, HEA_Color, HEA_Plate, HEA_ParkArea, HEA_Care, HEA_Height, HEA_Weight, HEA_History1, HEA_History2, HEA_History3, HEA_History4, HEA_History5, HEA_History6, HEA_History7, HEA_History8, HEA_History9, HEA_History10, HEA_History11, HEA_History12, HEA_History13, HEA_History14, HEA_History15, HEA_History16, HEA_OtherIll, HEA_HistoryDetails, HEA_HospName, HEA_HospPhone, HEA_PhyName1, HEA_PhyAddress1, HEA_PhyPhone1, HEA_PhyFax1, HEA_PhyEmail1, HEA_PhySpecialty1, HEA_PhyName2, HEA_PhyAddress2, HEA_PhyPhone2, HEA_PhyFax2, HEA_PhyEmail2, HEA_PhySpecialty2, HEA_OtherAll, HEA_OtherDetails, HEA_Pendant, HEA_Storage

 ,HEA_LivingWill            
  ,HEA_Medical_Power_Attorney
  ,HEA_POLST                 
  ,HEA_MOST                  
  ,HEA_DNR     )              

 VALUES 
 ('$RES_ID', '$USR_ID', '$HEA_DateStamp','$HEA_Vision', '$HEA_Hearing', '$HEA_Mobility', '$HEA_Falls', '$HEA_Food', '$HEA_FoodPref', '$HEA_FoodDetails', '$HEA_Insect', '$HEA_InsectDetails', '$HEA_Driver', '$HEA_Make', '$HEA_Model', '$HEA_Year', '$HEA_Color', '$HEA_Plate', '$HEA_ParkArea', '$HEA_Care', '$HEA_Height', '$HEA_Weight', '$HEA_History1', '$HEA_History2', '$HEA_History3', '$HEA_History4', '$HEA_History5', '$HEA_History6', '$HEA_History7', '$HEA_History8', '$HEA_History9', '$HEA_History10', '$HEA_History11', '$HEA_History12', '$HEA_History13', '$HEA_History14', '$HEA_History15', '$HEA_History16', '$HEA_OtherIll', '$HEA_HistoryDetails', '$HEA_HospName', '$HEA_HospPhone', '$HEA_PhyName1', '$HEA_PhyAddress1', '$HEA_PhyPhone1', '$HEA_PhyFax1', '$HEA_PhyEmail1', '$HEA_PhySpecialty1', '$HEA_PhyName2', '$HEA_PhyAddress2', '$HEA_PhyPhone2', '$HEA_PhyFax2', '$HEA_PhyEmail2', '$HEA_PhySpecialty2', '$HEA_OtherAll', '$HEA_OtherDetails', '$HEA_Pendant', '$HEA_Storage' 

 ,'$HEA_LivingWill'          //please also note i have tried without the single quotes for these 5 variables
 ,'$HEA_Medical_Power_Attorney'
 ,'$HEA_POLST'                 
 ,'$HEA_MOST'                  
 ,'$HEA_DNR'                
 )") or die ("Error - No record creation"); 

我确定我遗漏了一些细节,请让我知道我还能提供什么。

这是HEALTH表的结构:

USE [KCustom]
GO

/****** Object:  Table [dbo].[Health]    Script Date: 6/19/2013 10:17:16 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Health](
    [HEA_ID] [int] IDENTITY(1,1) NOT NULL,
    [RES_ID] [int] NULL,
    [HEA_LastUser] [int] NULL,
    [HEA_DateStamp] [datetime] NULL,
    [HEA_Vision] [int] NULL,
    [HEA_Hearing] [int] NULL,
    [HEA_Mobility] [int] NULL,
    [HEA_Falls] [int] NULL,
    [HEA_Food] [varchar](5) NULL,
    [HEA_FoodPref] [int] NULL,
    [HEA_FoodDetails] [varchar](max) NULL,
    [HEA_Insect] [varchar](5) NULL,
    [HEA_InsectDetails] [varchar](max) NULL,
    [HEA_Driver] [varchar](5) NULL,
    [HEA_Make] [varchar](50) NULL,
    [HEA_Model] [varchar](50) NULL,
    [HEA_Year] [varchar](50) NULL,
    [HEA_Color] [varchar](50) NULL,
    [HEA_Plate] [varchar](50) NULL,
    [HEA_ParkArea] [varchar](50) NULL,
    [HEA_Care] [int] NULL,
    [HEA_Height] [varchar](50) NULL,
    [HEA_Weight] [varchar](50) NULL,
    [HEA_History1] [varchar](5) NULL,
    [HEA_History2] [varchar](5) NULL,
    [HEA_History3] [varchar](5) NULL,
    [HEA_History4] [varchar](5) NULL,
    [HEA_History5] [varchar](5) NULL,
    [HEA_History6] [varchar](5) NULL,
    [HEA_History7] [varchar](5) NULL,
    [HEA_History8] [varchar](5) NULL,
    [HEA_History9] [varchar](5) NULL,
    [HEA_History10] [varchar](5) NULL,
    [HEA_History11] [varchar](5) NULL,
    [HEA_History12] [varchar](5) NULL,
    [HEA_History13] [varchar](5) NULL,
    [HEA_History14] [varchar](5) NULL,
    [HEA_History15] [varchar](5) NULL,
    [HEA_History16] [varchar](5) NULL,
    [HEA_OtherIll] [varchar](500) NULL,
    [HEA_HistoryDetails] [varchar](max) NULL,
    [HEA_HospName] [varchar](500) NULL,
    [HEA_HospPhone] [varchar](500) NULL,
    [HEA_HospAddress] [varchar](max) NULL,
    [HEA_PhyName1] [varchar](max) NULL,
    [HEA_PhyAddress1] [varchar](max) NULL,
    [HEA_PhyPhone1] [varchar](max) NULL,
    [HEA_PhyFax1] [varchar](max) NULL,
    [HEA_PhyEmail1] [varchar](max) NULL,
    [HEA_PhySpecialty1] [varchar](max) NULL,
    [HEA_PhyName2] [varchar](max) NULL,
    [HEA_PhyAddress2] [varchar](max) NULL,
    [HEA_PhyPhone2] [varchar](max) NULL,
    [HEA_PhyFax2] [varchar](max) NULL,
    [HEA_PhyEmail2] [varchar](max) NULL,
    [HEA_PhySpecialty2] [varchar](max) NULL,
    [HEA_OtherAll] [varchar](5) NULL,
    [HEA_OtherDetails] [varchar](max) NULL,
    [HEA_RespParty] [varchar](max) NULL,
    [HEA_MovedFrom] [int] NULL,
    [HEA_PersonRespName] [varchar](max) NULL,
    [HEA_PersonRespAddress] [varchar](max) NULL,
    [HEA_PersonRespPhone] [varchar](max) NULL,
    [HEA_PersonRespEmail] [varchar](max) NULL,
    [HEA_PersonRespGuardian] [int] NULL,
    [HEA_PersonRespPOA] [int] NULL,
    [HEA_PersonRespPayee] [int] NULL,
    [HEA_DentistName] [varchar](max) NULL,
    [HEA_DentistAddr] [varchar](max) NULL,
    [HEA_DentistPhone] [varchar](max) NULL,
    [HEA_DentistEmail] [varchar](max) NULL,
    [HEA_CaseName] [varchar](max) NULL,
    [HEA_CaseAddr] [varchar](max) NULL,
    [HEA_CasePhone] [varchar](max) NULL,
    [HEA_CaseEmail] [varchar](max) NULL,
    [HEA_Pendant] [varchar](50) NULL,
    [HEA_Storage] [varchar](50) NULL,
    [HEA_LivingWill] [bit] NULL,
    [HEA_Medical_Power_Attorney] [bit] NULL,
    [HEA_POLST] [bit] NULL,
    [HEA_MOST] [bit] NULL,
    [HEA_DNR] [bit] NULL,
 CONSTRAINT [PK_Health] PRIMARY KEY CLUSTERED 
(
    [HEA_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

请注意$_POST[] variables正在从上一页抓取。这里是这些变量起源的整个第一页的来源。

如果您想查看执行 的页面的完整源代码INSERT,这里就是。

我确实放了:

or var_dump($create_info);  

代替or die(...);

尽管没有出错,但也没有执行任何操作

我也尝试过放置

,1,1,1,1,1            
 )") or die ("Error - No record creation"); 

代替:

 ,$HEA_LivingWill          
 ,$HEA_Medical_Power_Attorney
 ,$HEA_POLST 
 ,$HEA_MOST                  
 ,$HEA_DNR  )") or die ("Error - No record creation"); 

结果没有变化。记录不受影响

4

2 回答 2

1

请尝试插入:

$create_info = mssql_query("INSERT INTO 
Health 
(RES_ID, HEA_LastUser, HEA_DateStamp, HEA_Vision, HEA_Hearing, HEA_Mobility, HEA_Falls, HEA_Food, HEA_FoodPref, HEA_FoodDetails, HEA_Insect, HEA_InsectDetails, HEA_Driver, HEA_Make, HEA_Model, HEA_Year, HEA_Color, HEA_Plate, HEA_ParkArea, HEA_Care, HEA_Height, HEA_Weight, HEA_History1, HEA_History2, HEA_History3, HEA_History4, HEA_History5, HEA_History6, HEA_History7, HEA_History8, HEA_History9, HEA_History10, HEA_History11, HEA_History12, HEA_History13, HEA_History14, HEA_History15, HEA_History16, HEA_OtherIll, HEA_HistoryDetails, HEA_HospName, HEA_HospPhone, HEA_PhyName1, HEA_PhyAddress1, HEA_PhyPhone1, HEA_PhyFax1, HEA_PhyEmail1, HEA_PhySpecialty1, HEA_PhyName2, HEA_PhyAddress2, HEA_PhyPhone2, HEA_PhyFax2, HEA_PhyEmail2, HEA_PhySpecialty2, HEA_OtherAll, HEA_OtherDetails, HEA_Pendant, HEA_Storage

,HEA_LivingWill            
,HEA_Medical_Power_Attorney
,HEA_POLST                 
,HEA_MOST                  
,HEA_DNR     )              

VALUES 
($RES_ID, $USR_ID, '$HEA_DateStamp',$HEA_Vision, $HEA_Hearing, $HEA_Mobility, $HEA_Falls, '$HEA_Food', $HEA_FoodPref, '$HEA_FoodDetails', '$HEA_Insect', '$HEA_InsectDetails', '$HEA_Driver', '$HEA_Make', '$HEA_Model', '$HEA_Year', '$HEA_Color', '$HEA_Plate', '$HEA_ParkArea', $HEA_Care, '$HEA_Height', '$HEA_Weight', '$HEA_History1', '$HEA_History2', '$HEA_History3', '$HEA_History4', '$HEA_History5', '$HEA_History6', '$HEA_History7', '$HEA_History8', '$HEA_History9', '$HEA_History10', '$HEA_History11', '$HEA_History12', '$HEA_History13', '$HEA_History14', '$HEA_History15', '$HEA_History16', '$HEA_OtherIll', '$HEA_HistoryDetails', '$HEA_HospName', '$HEA_HospPhone', '$HEA_PhyName1', '$HEA_PhyAddress1', '$HEA_PhyPhone1', '$HEA_PhyFax1', '$HEA_PhyEmail1', '$HEA_PhySpecialty1', '$HEA_PhyName2', '$HEA_PhyAddress2', '$HEA_PhyPhone2', '$HEA_PhyFax2', '$HEA_PhyEmail2', '$HEA_PhySpecialty2', '$HEA_OtherAll', '$HEA_OtherDetails', '$HEA_Pendant', '$HEA_Storage' 

,$HEA_LivingWill          
,$HEA_Medical_Power_Attorney
,$HEA_POLST                 
,$HEA_MOST                  
,$HEA_DNR                
)") or die ("Error - No record creation"); 

如果还是不行,请var_dump($create_info)在查询后执行。

于 2013-06-20T06:05:59.877 回答
-1
$HEA_LivingWill  = ($_POST['HEA_LivingWill'] =='on')  ? 1 : 0;

您需要将 False/True 值转换为 0/1。SQL Server 不会为您执行此隐式转换。

于 2013-06-20T05:11:49.740 回答