Hi brothers Im newbie in databases. im trying to insert one query in database but keeps showing error INSERT INTO `Options` (` Name`, `Surname`,` Grade`, `Address`,` City`) VALUES (‘Adi’, ‘Test’, ‘ 2 ‘, ”, NULL), (‘Andy’ , ‘User’, ‘ 100500 ‘, ”, NULL); Code (markup): what i have done wrong?
You're trying to insert two rows at once. It doesn't work that way. That should be two SEPARATE queries. Which is where bind/execute in languages like PHP also becomes handy. The presence of "styled quotes" probably isn't helping. You've got ‘ and ’ mixed. Really though that's why I avoid doing anything that requires backtick quotes in my queries altogether. I also suggest you avoid mixing upper and lower case in your fieldnames / table names. Some backup software can screw that up if you end up on winblows. So something like: /* assuming $db is a connected PDO object */ $stmt = $db->prepare(' INSERT INTO options ( name, surname, grade, address, city ) VALUES ( ?, ?, ?, ?, ? ) '); $stmt->execute(['Adi', 'Test', 2, '', null]); $stmt->execute(['Andy', 'User', 100500, '', null]); Code (markup): Assuming you're working in a language designed to do queries "properly" it should look something like that. It's called -- or was twenty-five years ago -- POEM. Prepare Once, Execute Mostly. There's some new-fangled name for it I can never remember.
Because you're using MySQL you should be using something like the pdo library and following @deathshadow's advice. Technically your query is still valid but it's insecure and therefore you don't do it that way. The most glaring problem I could see was spaces between the ` and the column name.
Not sure what the structure has to do with it. What server side language are you controlling your SQL from?
That "key" with "mul" for name and surname... is that a multi column primary key? Always have an id for your primary name + surname is flawed because you will have people with the same name people change their surname on marriage people change their first names - William becomes Bill, people switch to using their middle names I appreciate that concerns about name + surname are based on anglo culture and I know little about Algeria but I am aware of the Muslim tendency to call boys Mohammed something - the spelling seems to have many variations but it increases the probability of duplication.
Try this please: INSERT INTO `Options` ( Name, Surname, Grade, Address, City) VALUES (‘Adi’, ‘Test’, ‘2‘, '', ''), (‘Andy’, ‘User’, ‘100500‘, '', NULL); In the query you posted, the column before NULL is a double quote sign. It should be 2 single quotes. What is the error you are getting anyways?