Daryl
Daryl

Reputation: 51

phpmyadmin mysql INSERT statement syntax error

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?

Upvotes: 1

Views: 3124

Answers (2)

Adi Inbar
Adi Inbar

Reputation: 12321

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.

Upvotes: 0

pEte wEntz Mendoza
pEte wEntz Mendoza

Reputation: 53

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

if its string dont forget to use single quotation

Upvotes: 1

Related Questions