rony2006 Posted November 16, 2015 Posted November 16, 2015 Hello, can somebody help me with an exemple to send the data from the form below to mysql database? #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 296, 167, 192, 124) $Input1 = GUICtrlCreateInput("", 112, 48, 121, 21) $Input2 = GUICtrlCreateInput("", 112, 80, 121, 21) $Label1 = GUICtrlCreateLabel("Name:", 72, 56, 35, 17) $Label2 = GUICtrlCreateLabel("Last name:", 56, 80, 56, 17) $Button1 = GUICtrlCreateButton("Send", 128, 120, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I am using this MYSQL udf https://www.autoitscript.com/forum/topic/20814-mysql-udfs/And I have a database with table "table" and 2 colums: "name" and "lastname" Thank you.
Developers Jos Posted November 16, 2015 Developers Posted November 16, 2015 You must have tried more than this ..right?There is nothing there yet with relation to reading the control values and trying to add it to your DB.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
alexandruc Posted November 16, 2015 Posted November 16, 2015 (edited) rony2006,first use GUICtrlRead to read the user input from your form (https://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm).Then you can either send the data to a web page (https://www.autoitscript.com/forum/topic/147621-http-get-and-post-request-as-simple-as-possible/) then process the data to mysql on the server side, or you can use the mysql UDF to remote connect to your db but this seems to be a lot more complicated procedure.If the script you are trying to build will be shared with other users it implies security risks as the db credentials will be inside the autoit script. So, if your not the only user of the script I would recommend you send the date to a page and then process the data as you see fit. Edited November 16, 2015 by alexandruc
rony2006 Posted November 16, 2015 Author Posted November 16, 2015 Thanks!And yes, I want this application to be used by many users because if I was the only user than sqlite was easyer.
Moderators JLogan3o13 Posted November 16, 2015 Moderators Posted November 16, 2015 @rony2006 if you Google "db credentials" does it perhaps give you an idea of what alexandruc was telling you?? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
rony2006 Posted November 17, 2015 Author Posted November 17, 2015 Ok, so I made this code and everything worked fine until I tried to send the data from the input "intrare" in my database:expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "EzMySql.au3" #include <Array.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 172, 97, 192, 124) Global $intrare = GUICtrlCreateInput("intrare", 32, 24, 121, 21) Global $trimite = GUICtrlCreateButton("trimite", 48, 56, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #include "EzMySql.au3" #include <Array.au3> If Not _EzMySql_Startup() Then MsgBox(0, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg()) Exit EndIf $Pass = "" If Not _EzMySql_Open("127.0.0.1", "root", $Pass, "ifm", "3306") Then MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg()) Exit EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $trimite ;mai jos scriu ce sa se intample in CAZ ca se apasa butonul trimite $datafromuser = GUICtrlRead($intrare) MsgBox (1, $datafromuser, "test") $sMySqlStatement = "INSERT INTO `piese_de_schimb` (`id`, `denumire`, `tip`) VALUES (NULL, "$datafromuser", 'ver4564de');" If Not _EzMySql_Exec($sMySqlStatement) Then MsgBox(0, "Error Creating Database Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg()) Exit EndIf _EzMySql_Close() _EzMySql_ShutDown() Exit EndSwitch WEnd If i use $sMySqlStatement = "INSERT INTO `piese_de_schimb` (`id`, `denumire`, `tip`) VALUES (NULL, 'pen'), 'ver4564de');" If Not _EzMySql_Exec($sMySqlStatement) Then MsgBox(0, "Error Creating Database Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg()) Exit EndIf is working ok, but if I remplace 'pen' with "$datafromuser" or $datafromuser I get an error.What I do wrong? I want the data that I write in input box to be sent to my database in table piese_de_schimb.P.S. I am using https://www.autoitscript.com/forum/topic/116072-ezmysql-udf-use-mysql-databases-with-autoit/
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now