Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mysql

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

like image 742
Nettai manoj Avatar asked Mar 26 '13 07:03

Nettai manoj


2 Answers

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

like image 133
Hardik Avatar answered Sep 30 '22 14:09

Hardik


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

'[email protected]'

That's it bro.

like image 29
Fadi Obaji Avatar answered Sep 30 '22 14:09

Fadi Obaji