简体   繁体   中英

what data type should i use to store email in mysql database?

I have a small website and I want to store the email of my contacts in a MySQL database. I am using PHP and MySQL. Each time I try, it gives me following error. However when I remove the @ and . (dot) it works fine. I really need a help on this one, please tell me what mistake I am doing and it would be very helpful if the code is given.

I already used VARCHAR only. It keeps showing up the error below:

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 '@gmail.com( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(3' at line 1

Use varchar and wrap the email in quotes so it can be treated as a string like so:

'Email@gmail.com'

That's it bro.

you can use vachar datatype with 1-255 length.

And for more information if your value's length is more then 255 then use text datatype

Besides the error with the @, you still have a query that won't work: gmail.com( id INT.... shouldn't that be gmail.com', ( id INT....?

The fact that your database can't handle a @ can be caused by the characterset of the database. Is it UTF-8 Unicode (utf8)? And what is the type of the record where you want to store the mail?

a varchar(50 ) would be enough for storing email..

Then in your query all the values to insert must wrapped by '' or ""

eg

$sql='INSERT INTO TABLE1 VALUES("Value1","EMAIL@GMAIL.com","VALUES3")'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM