Can not update mysql using Golang

All,

I’ve been using a tutorial (http://www.golangprograms.com/advance-programs/example-of-golang-crud-using-mysql-from-scratch.html)
Was able to create the application. I am able to update de employee, but I cannot create a new employee using te webinterface.
Is there a error in the code? I cannot find it

Hi. Do you get any output in the terminal from the program? Do you see the output of the following line?

log.Println("INSERT: Name: " + name + " | City: " + city)

Yes I do see that.
In MySQL I don’t see any changes though!

Checked again. What I see in Go is:
2018/11/24 18:29:47 INSERT: Name: My name | City: My citty

Do you see the change on the index page? How do you look at the table in MySQL, MySQL workbench?

I don’t see any changes. Not even on the index page. I look at the SQL table using MqSQL Workbench.
If I run the code, I am able to edit, delete and do see changes (in both the index paga as the MySQL table). When I want to add and choose “new” no changes are made.

Strange. Do the user you use in the program have rights to do inserts in the table? It should really fail with an error in the program but just check it. If you run with root is as all rights from the beginning so you don’t need to check.

I run with root…
Exactly copied the code from the website I mentioned…

insForm.Exec(name, city… Can also return an error an error. Could you check for this?

I guess I found it. I added the colum Id for a new entry
Added it in the template and in the main folder. Now I was able to add new person.

1 Like

Good work!

But you shouldn’t have to because the field

`id` int(6) unsigned NOT NULL AUTO_INCREMENT,

is autoincrementing itself on every insert.

You’re right
I checked again and found out that de Auto increment option wasn’t turned on in MqSQL.
I did create te db manually and seemed to have forgotten this……

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.