Home Backend Development PHP Tutorial 这条插入记录的语句有什么错?该怎么处理

这条插入记录的语句有什么错?该怎么处理

Jun 13, 2016 pm 01:36 PM
datetime varchar

这条插入记录的语句有什么错?
我有一个地方插入一条数据库记录,报错:
insert into receipt(rent,deposit,paidup,createdtime,depositback,coperator) values(50,1,51,'2012-04-10 17:44:47','0','zxy')You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '17:44:47' at line 1

时间是从$dt=date("Y-m-d H:i:s");得到的。
我去查这条记录实际上已经被插入表receipt了.

下面是从phpmyadmin拷贝出来的有用的表结构:
字段 类型 空 默认 额外
id int(11) 否 无 AUTO_INCREMENT
rent float 否 无
deposit float 否 无
paidup float 否 无  
depositback varchar(1) 否 无
createdtime datetime 否 无
coperator varchar(30) 否 无  
dbtime datetime 是 NULL
dboperator varchar(30) 是 NULL

为什么出错了还能插入成功呀?
这个错什么意思呀?

------解决方案--------------------
看着不应该出错,很蹊跷。
我怀疑createdtime是date类型,而不是datetime. 因为date类型正好只接受2012-04-10 17:44:47 前面的2012-04-10。而datetime类型接受 2012-04-10 17:44:47

尽管是phpmyadmin的查询结果,但仍然有必要建议你运行以下SQL语句
SHOW CREATE TABLE `receipt`;
看看结果
------解决方案--------------------



你可以贴出$database类里面,拼装出来的SQL语句
------解决方案--------------------
没遇到这样的怪事。
我做了个测试,同样的表结构,同样的SQL语句,没有遇到任何问题
------解决方案--------------------
测试过是正常的。要注意的是
$rent,$deposit,$total,'$dt'的值要存在,不存在的话组成的sql就有问题。导致错误。
------解决方案--------------------
Column count doesn't match value count 那是你书写错误,比如 insert into tablename(a, b, c) VALUES ('avalue', 'bvalue') 少了个列的值。仔细检查语法

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert DateTime to integer in Python? How to convert DateTime to integer in Python? Sep 05, 2023 pm 10:21 PM

The manipulation of date and time values ​​is an important aspect of programming, and the Python language provides a useful built-in module for this called datetime. However, in some cases, you may need to convert a DateTime object to an integer value in order to perform specific operations or calculations. There are multiple ways to convert a DateTime to an integer in Python, each with its own advantages and disadvantages. In this article, we'll take a closer look at these methods and examine when each method is appropriate to use. After reading this article, you will have a complete understanding of how to efficiently convert DateTime objects to integers in Python and be able to choose the most appropriate method for your specific programming task. Method 1: Use timestamp

Get today's date using DateTime.Today function in C# Get today's date using DateTime.Today function in C# Nov 18, 2023 pm 12:41 PM

Getting today's date using DateTime.Today function in C# requires specific code examples C# is an object-oriented programming language that provides many built-in classes and methods to handle dates and times. Among them, the DateTime class has some very useful methods, such as the Today property, which can be used to obtain today's date. Here is a sample code that demonstrates how to get today's date using the DateTime.Today function in C#: usingSystem;

How to use DateTime in Python How to use DateTime in Python Apr 19, 2023 pm 11:55 PM

All data are automatically assigned a "DOB" (Date of Birth) at the beginning. Therefore, it is inevitable to encounter date and time data when processing data at some point. This tutorial will take you through the datetime module in Python and using some peripheral libraries such as pandas and pytz. In Python, anything related to date and time is handled by the datetime module, which further divides the module into 5 different classes. Classes are simply data types that correspond to objects. The following figure summarizes the 5 datetime classes in Python along with commonly used attributes and examples. 3 useful snippets 1. Convert string to datetime format, maybe using datet

Use the DateTime.AddDays function in C# to add a specified number of days to a date Use the DateTime.AddDays function in C# to add a specified number of days to a date Nov 18, 2023 pm 03:08 PM

Use the DateTime.AddDays function in C# to add a specified number of days to a date. In C# programming, we often encounter situations where we need to add and subtract dates. The DateTime class in C# provides many convenient methods and properties for working with dates and times, including the AddDays function, which can be used to add a specified number of days to a specified date. Here is a specific code example that demonstrates how to use the DateTime.AddDays function to add a specified number of days to a date:

What are the options for calendar and date libraries in Python? What are the options for calendar and date libraries in Python? Oct 21, 2023 am 09:22 AM

There are many excellent calendar libraries and date libraries in Python for us to use. These libraries can help us handle date and calendar related operations. Next, I will introduce you to several common choices and provide corresponding code examples. Datetime library: Datetime is Python's built-in date and time processing module. It provides many date and time related classes and methods, which can be used to process dates, times, time differences and other operations. Sample code: importdatetime#Get the current date

What to do if mysql datetime error occurs What to do if mysql datetime error occurs Feb 15, 2023 am 10:12 AM

Solution to mysql datetime error: 1. Change datetime to timestamp timestamp; 2. Upgrade MySQL to a higher version; 3. Execute the "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root1' PASSWORD EXPIRE NEVER;" command That’s it.

PHP formats a GMT/UTC date/time PHP formats a GMT/UTC date/time Mar 21, 2024 am 10:41 AM

This article will explain in detail how to format a GMT/UTC date/time with PHP. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Introduction to Formatting GMT/UTC Date/Time in PHP In PHP, formatting GMT/UTC date/time is crucial for correctly displaying and handling cross-time zone dates. This article will explain how to format a GMT/UTC date/time using PHP's DateTime class, as well as the various formatting options available. DateTime class The DateTime class represents a date and time. It can store and manipulate date/time values ​​in time zones such as GMT/UTC. To create a new Da

Symphony of Time: The timestamp mystery of the PHP DateTime extension Symphony of Time: The timestamp mystery of the PHP DateTime extension Mar 08, 2024 am 10:13 AM

The Nature of a DateTime Timestamp In the PHPDateTime extension, a timestamp is a numeric value that represents a specific point in time, usually in the form of a UNIX timestamp, which is the number of seconds that have elapsed since January 1, 1970 00:00:00 UTC. The Mystery of Timestamps: UTC and Time Zones One of the mysteries of DateTime timestamps is that it uses the UTC (Coordinated Universal Time) time zone by default. This means that the timestamp you get may differ from your local time zone. For example, if you get a timestamp in Pacific Time (UTC-8), it will be 8 hours behind local time. To solve this mystery, you can use the DateTime::setTimestamp() method to specify a specific

See all articles