Jump to content

Recommended Posts

Posted

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.

Posted (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 by alexandruc
Posted

Ok, so I made this code and everything worked fine until I tried to send the data from the input "intrare" in my database:

#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/

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...