Error when inserting datetime into SQL [closed] - mysql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am having a problem inserting a datetime into SQL. my statement is...
INSERT INTO `booking.com`.`last_sign_in` (`personID`, `browser`,
`deviceType`, `deviceOS`, `location`, `time`) VALUES ('1', 'chrome
61', 'desktop', 'windows 10', 'Belfast', '20171114 10:34:09 AM');
When I try to run this insert statement I get the error...
all help appreciated!!

Try this
INSERT INTO `booking.com`.`last_sign_in` (`personID`, `browser`, `deviceType`, `deviceOS`, `location`, `time`)
VALUES (1, 'chrome 61', 'desktop', 'windows 10', 'Belfast', '2017-11-14 10:34:09');
The dates have been changed to the correct format (dashes added and the AM removed) also, it looks like you're trying to add the string value '1' into the PersonID column which I am assuming is int so I have changed that to an int value based on that assumption

Related

how do i deal with missing string in MySQL? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I want to insert data into my table but when I press "enter" nothing happens and the next sentence starts with '>.
I know it means missing string but I don't see it
this is my code
INSERT
INTO events
VALUES
('13', '2021.03.13',
'vet',
'Dehidration. Spider's body loses more fluids than it does take in. If spider is not threated, it can get worse and become a serious problem.',
'10',
'5');
then it shows "'>"
how to deal with this?
The fourth value that you are entering contains a ' which is closing the string early, try this;
INSERT
INTO events
VALUES
('13', '2021.03.13',
'vet',
'Dehydration. Spider\'s body loses more fluids than it does take in. If spider is not threated, it can get worse and become a serious problem.',
'10',
'5');
In this case the \ lets the database know that you want to store the character ', instead of ending the string early.
Please use this mysqli_real_escape_string(db_connection, $your_string)
OR
you may write single quote like this => \'

MySQL WHERE IN and another variable equal [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm running the following query expecting to receive back the first 3 rows, however all I am getting is the first row.
Query Ran
SELECT * FROM inventories WHERE id IN ('1,2,3') AND state = 1
Database
Result
[ RowDataPacket {
id: 1,
uid: 1,
name: 'An Epic Item',
suggested_price: 29212,
image: 'http://hanatemplate.com/images/emoji-ok-7.png',
state: 1 } ]
Why is it not returning the first three rows instead of just the first one?
It shouldn't return any, since you've got the list enclosed in quotes (but see below). Try
SELECT * FROM inventories WHERE id IN (1,2,3) AND state = 1
As per the comments, SQL converts your string to an integer, 1, which is why you get the first record.

How can I fix the Syntax Error in the subquery? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to find the Age based off date of birth. I keep getting a syntax error in the subquery.
I'm getting on error on the - CUST_DOB /365,0) As Age from customer; to use the correct syntax. Error Code 1064
SELECT CUST_LNAME, CUST_FNAME, ROUND((NOW() – CUST_DOB)/365,0) AS AGE
FROM CUSTOMER;
There is a problem with the minus (-) sign. please use it like
SELECT CUST_LNAME, CUST_FNAME, ROUND((NOW() - CUST_DOB)/365,0) AS AGE
FROM CUSTOMER;

How to fetch mysql data having brackets? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to fetch mysql data having round brackets e.g. ABCD(XYZ). When I run query
"SELECT * FROM tablename WHERE Column = 'ABCD(XYZ)'"
it returns an empty result. Please suggest a way. Thanks in advance!
this should work:
INSERT INTO `tablename` (`Column`) VALUES ('ABCD(XYZ)');
SELECT * FROM `tablename` WHERE `Column` = 'ABCD(XYZ)'";
Maybe 'ABCD(XYZ)' is not exactly the value of your data (for example if you inserted some whitespaces before or after it.)
You can try it with a like to find that out:
SELECT * FROM `tablename` WHERE `Column` LIKE '%ABCD(XYZ)%'";
Another possibility is that your value has been converted with htmlentities and you saved something like this:
'ABCD&40;XYZ&41;'
&40; Left parenthesis
&41; Right parenthesis

How to insert a new row into a MySQL database? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to insert values into a mysql database using the following query:
INSERT INTO TestTable (SearchTerm, SearchResult)
VALUES (?, ?), ("TestTerm", "TestResult");
I get the error message that there is an error "near '?, ?) ("TestTerm", "TestResult")' at line 1".
Would someone mind pointing out my mistake?
The ? is used with frameworks like PDO and mysqli. A normal insert looks like this
INSERT INTO TestTable (SearchTerm, SearchResult)
VALUES ('TestTerm', 'TestResult');
or
INSERT INTO TestTable (SearchTerm, SearchResult)
SELECT 'TestTerm', 'TestResult';
Script direct:
INSERT INTO TestTable (SearchTerm, SearchResult)
VALUES ("TestTerm", "TestResult");
With prepared statements:
INSERT INTO TestTable (SearchTerm, SearchResult) VALUES (?, ?);
It looks like you're trying to use a perpared statement. The idea is that the question marks stand in for values that may contain query-breaking character (namely semi-colons and quotes).
If you're using a library, you usually need to use two steps to do this. E.g., in java:
PreparedStatement ps = new PreparedStatement( "INSERT INTO TestTable (SearchTerm, SearchResult) VALUES (?, ?)");
ps.execute("TestTerm", "TestResult");
ps.execute("Escaped;Term", "TestResult"); // the semicolon will be escaped for you
Most every language has generic SQL libraries that allow you to do this. What language are you using?