I'm reading a MySQL query input from a form:
<h1>MySQL Page</h1>
<small>Perform queries and edit the database from here</small>
<form method="get" action="">
<label for="sqlQuery">MySQL Query:</label>
<input type="text" id="sqlQuery" name="sqlQuery">
<button type="submit">Perform Query</button>
</form>
After that I want to display the results on the same page using GoLang, however it keeps telling me that:
# command-line-arguments
./sql.go:128: cannot convert results (type sql.Result) to type string
Please keep in mind, this is the first golang app I've ever written so I apologize if this is a simple issue, here is the golang code:
func sqlQueryHandler(response http.ResponseWriter, request *http.Request){
userName := getUserName(request)
db, err := sql.Open("mysql", userName)
fmt.Fprintf(response, sqlPage)
sqlCommand := request.FormValue("sqlQuery")
//fmt.Fprintf(response, sqlCommand)
if err != nil {
fmt.Fprintf(response, "
An error occured during your MySQL command: %s", err)
panic(err)
} else {
data, err := db.Exec(sqlCommand)
if err != nil {
http.Redirect(response, request, "/error", 302)
} else {
// display the output of the sql query here
}
}
}