1

I don't know what's wrong, why my statement won't insert. I have the following data:

username varchar length (25)
password varchar length (25)
fname varchar length (25)
email text
contactnum big int (30)

I don't know why my email is not inserting along with my contactnum here's the screenshot: enter image description here

Based on what I understand the length is the number of characters in a data one can enter right?

What seems to be wrong on my query?

2 Answers 2

1
INSERT INTO members (username, password, fname, email, contactnum)
VALUES (2, 2, 2, '[email protected]', 1)

if its string dont forget to use single quotation

Sign up to request clarification or add additional context in comments.

Comments

0

The string value you're inserting into the email filed needs to be quoted. Also, the names of the table and columns shouldn't be quoted. The query should look like this:

INSERT INTO members (username, password, fname, email, contactnum)
VALUES (2, 2, 2, '[email protected]', 1)

Note that the first three fields you're changing are declared as varchar, so you should be inserting strings into them as well. The reason you're not getting errors for trying to insert integers into varchar fields is that in some cases the wrong data type can be automatically converted. I think it's better practice not to rely on implicit type conversions, to avoid errors and unexpected results, so the query really should be written this way:

INSERT INTO members (username, password, fname, email, contactnum)
VALUES ('2', '2', '2', '[email protected]', 1)

That's a matter of opinion, though. They both work.

3 Comments

Thanks :) am i right? about the length values, is the character count(digits) that you can enter? for example int age lenth value (2), you can only enter two digit like 11, entering 111 will give an error right?
@Daryl Correct, the length is the maximum number of characters allowed in the field.
@MichalČihař Yes, you're right, thanks. I'll remove that advice (which was kind of an aside anyway, not really part of the answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.