❔ SQL syntax error - INSERT INTO statement

query looks like this
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
get a syntax error please keep in mind this is something for school, stuff like SQL Injections and other new features are dismissible thanks in advance, benAmi
12 Replies
המשורר
המשוררOP2y ago
!eval
MODiX
MODiX2y ago
That command had an error
BadArgCount: The input text has too few parameters.
Remove your reaction to delete this message
MODiX
MODiX2y ago
benAmi#6360
REPL Result: Failure
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Exception: CompilationErrorException
- The name 'fname' does not exist in the current context
- The name 'username' does not exist in the current context
- The name 'email' does not exist in the current context
- The name 'password' does not exist in the current context
- The name 'age' does not exist in the current context
- The name 'gender' does not exist in the current context
- The name 'state' does not exist in the current context
- The name 'fname' does not exist in the current context
- The name 'username' does not exist in the current context
- The name 'email' does not exist in the current context
- The name 'password' does not exist in the current context
- The name 'age' does not exist in the current context
- The name 'gender' does not exist in the current context
- The name 'state' does not exist in the current context
Compile: 522.125ms | Execution: 0.000ms | React with ❌ to remove this embed.
המשורר
המשוררOP2y ago
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
string password = "Moshe";
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
string password = "Moshe";
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
!eval
MODiX
MODiX2y ago
That command had an error
BadArgCount: The input text has too few parameters.
Remove your reaction to delete this message
MODiX
MODiX2y ago
benAmi#6360
REPL Result: Failure
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
Exception: CompilationErrorException
- The name 'password' does not exist in the current context
- The name 'password' does not exist in the current context
Compile: 672.142ms | Execution: 0.000ms | React with ❌ to remove this embed.
MODiX
MODiX2y ago
benAmi#6360
REPL Result: Failure
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
string password = "Moshe"
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
string password = "Moshe"
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
Exception: CompilationErrorException
- ; expected
- ; expected
Compile: 712.386ms | Execution: 0.000ms | React with ❌ to remove this embed.
MODiX
MODiX2y ago
benAmi#6360
REPL Result: Success
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
string password = "Moshe";
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
string fname = "Moshe";
string username = "Moshe";
string email = "[email protected]";
string age = "124";
string gender = "Moshe";
string password = "Moshe";
int state = 1;
string query = $"INSERT INTO users " +
$"(fname, username, email, password, age, gender, state) " +
$"VALUES ({fname}, {username}, {email}, {password}, {age}, {gender}, {state})";
Console.WriteLine(query);
Console Output
INSERT INTO users (fname, username, email, password, age, gender, state) VALUES (Moshe, Moshe, [email protected], Moshe, 124, Moshe, 1)
INSERT INTO users (fname, username, email, password, age, gender, state) VALUES (Moshe, Moshe, [email protected], Moshe, 124, Moshe, 1)
Compile: 607.958ms | Execution: 83.025ms | React with ❌ to remove this embed.
המשורר
המשוררOP2y ago
Any help please?
Angius
Angius2y ago
Strings in SQL need to be quoted So it has to be 'Moshe' not Moshe And so on Prepared statements will take care of that for you
Ⰽⰰⱈⰻⰽⱄ
Not only quoted, but also escaped to prevent SQL injection, bezt way to do that is by using Prepared statement as was mentioned before
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server