Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Inserting a variable into MySQL with Go

I have these 2 variables here

name := request.FormValue("username")
pass := request.FormValue("password")

I want to insert those 2 variables into my database

db.Query("INSERT INTO `godb` (`Username`, `Password`) VALUES (   )")

I tried (name,pass) ('name','pass') ($name, $pass) , none of them work.

Hope the question is not stupid, but I've been looking for solutions online but I did't understand them. Thanks !

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

From Using Prepared Statements

Parameter Placeholder Syntax

The syntax for placeholder parameters in prepared statements is database-specific. For example, comparing MySQL, PostgreSQL, and Oracle:

MySQL               PostgreSQL            Oracle
=====               ==========            ======
WHERE col = ?       WHERE col = $1        WHERE col = :col
VALUES(?, ?, ?)     VALUES($1, $2, $3)    VALUES(:val1, :val2, :val3)

You tried PostgreSQL syntax but you use MySQL.

over 4 years ago · Santiago Trujillo Report

0

query should be in this format db.Query("INSERT INTO table ($1, $2) VALUES (column1, column2)", value1, value2) in your case something like that db.Query("INSERT INTO godb ($1, $2) VALUES (username, password)", name, pass)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!