|
You last visited: Today at 19:18
Advertisement
Connect autoit to sql
Discussion on Connect autoit to sql within the AutoIt forum part of the Coders Den category.
05/03/2016, 04:20
|
#1
|
elite*gold: 0
Join Date: Oct 2013
Posts: 6
Received Thanks: 0
|
Connect autoit to sql
This is second question and last question.
Now I have database but How do I connect to the database.
Autoit can connect directly? or use php to login.
Now I use php to connect but I don't have knowledge about php.
can someone help me?
Code:
<?php
$condb = mysql_connect($host,$user,$pass) or die ("ERROR");
mysql_select_db($data,$condb);
$sql = "SELECT*FROM data2 WHERE Email = $email";
$check = mysql_query($sql);
$show = mysql_fetch_array($check);
if(!$show)
?>
I want to transfer $input in autoit to check email in database but i can't understand how to do that.
Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Send Text", 250, 162, 192, 124)
$Button1 = GUICtrlCreateButton("Send", 80, 128, 97, 25)
$Input1 = GUICtrlCreateInput("", 48, 32, 161, 21)
$Label1 = GUICtrlCreateLabel("Email", 112, 8, 23, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Global $email
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
And if correct user or wrong how to back to program
Help me pls it last step to complete my program.
|
|
|
05/03/2016, 16:18
|
#2
|
elite*gold: 0
Join Date: Sep 2010
Posts: 473
Received Thanks: 104
|
UPDATED
PHP code
Code:
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$dbase = 'test123';
$con = mysqli_connect($host, $user, $pass, $dbase);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL";
} else {
// check is email is in a link
if (isset($_GET['email'])) {
// protect email from mysql injection
$email = mysqli_real_escape_string($con, $_GET['email']);
// cleaned data
$email = clean_data($email);
// get email from database
$result = mysqli_query($con, "SELECT * FROM accounts WHERE email = '".$email."'");
if (mysqli_num_rows($result) > 0) {
echo 'ok';
}
mysqli_close($con); // close connection
}
}
// function to clean variable to prevent xss and code injection
function clean_data($data)
{
$invalid_characters = array("$", "%", "#", "<", ">", "|");
$data = strip_tags($data);
$data = trim($data);
$data = str_replace($invalid_characters, "", $data);
return $data;
}
?>
AutoIt code made with your example
Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <INet.au3>
#include <IE.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Send Text", 250, 162, 192, 124)
$Button1 = GUICtrlCreateButton("Send", 80, 128, 97, 25)
$Input1 = GUICtrlCreateInput("", 48, 32, 161, 21)
$Label1 = GUICtrlCreateLabel("Email", 112, 8, 23, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
checkLogin()
EndSwitch
WEnd
Func checkLogin()
Local $mail = GUICtrlRead($Input1) ; read email from input
Local $url = "http://playgame4.net/123.php?email=" ; url to check
Local $value = _INetGetSource ($url & $mail) ; get url with data
; check for value
If $value == 'ok' Then
MsgBox(0, "", "Valid email")
Else
MsgBox(0, "", "Invalid email")
EndIf
EndFunc
U can test, i made 2 emails

|
|
|
05/03/2016, 22:40
|
#3
|
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
|
Local $url = "http://yoursite/login.php?email=  or 1==1 will work
|
|
|
05/03/2016, 23:40
|
#4
|
elite*gold: 0
Join Date: Sep 2010
Posts: 473
Received Thanks: 104
|
On what u mean on php code ? u dont see its protected ?
|
|
|
05/04/2016, 03:01
|
#5
|
elite*gold: 0
Join Date: Oct 2013
Posts: 6
Received Thanks: 0
|
Quote:
Originally Posted by mlukac89
UPDATED
PHP code
Code:
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$dbase = 'test123';
$con = mysqli_connect($host, $user, $pass, $dbase);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL";
} else {
// check is email is in a link
if (isset($_GET['email'])) {
// protect email from mysql injection
$email = mysqli_real_escape_string($con, $_GET['email']);
// cleaned data
$email = clean_data($email);
// get email from database
$result = mysqli_query($con, "SELECT * FROM accounts WHERE email = '".$email."'");
if (mysqli_num_rows($result) > 0) {
echo 'ok';
}
mysqli_close($con); // close connection
}
}
// function to clean variable to prevent xss and code injection
function clean_data($data)
{
$invalid_characters = array("$", "%", "#", "<", ">", "|");
$data = strip_tags($data);
$data = trim($data);
$data = str_replace($invalid_characters, "", $data);
return $data;
}
?>
AutoIt code made with your example
Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <INet.au3>
#include <IE.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Send Text", 250, 162, 192, 124)
$Button1 = GUICtrlCreateButton("Send", 80, 128, 97, 25)
$Input1 = GUICtrlCreateInput("", 48, 32, 161, 21)
$Label1 = GUICtrlCreateLabel("Email", 112, 8, 23, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
checkLogin()
EndSwitch
WEnd
Func checkLogin()
Local $mail = GUICtrlRead($Input1) ; read email from input
Local $url = "http://playgame4.net/123.php?email=" ; url to check
Local $value = _INetGetSource ($url & $mail) ; get url with data
; check for value
If $value == 'ok' Then
MsgBox(0, "", "Valid email")
Else
MsgBox(0, "", "Invalid email")
EndIf
EndFunc
U can test, i made 2 emails

|
oh that work but in table i have 2 colume
email and serial.
if me check email it will back to send serial to check that email and serial are correct. How to make it?
serial = drivegetserial
why i check on my link Result=invalid
i tested on free host that all in valid
Quote:
Func checkLogin()
Local $mail = GUICtrlRead($Input1) ; read email from input
Local $url = "http://neowkickclick.siam.im/check.php?email=" ; url to check
Local $value = _INetGetSource ($url & $mail) ; get url with data
; check for value
If $value == 'ok' Then
MsgBox(0, "", "Valid email")
Else
MsgBox(0, "", "Invalid email")
EndIf
EndFunc
|
email
|
|
|
05/04/2016, 17:40
|
#6
|
elite*gold: 0
Join Date: Sep 2010
Posts: 473
Received Thanks: 104
|
Then u need to change all, so what exactly that script need to do ? You can add me on skype ( mario.lukacic.or ) if u have it, or facebook  so i can explain u better.
|
|
|
05/04/2016, 20:08
|
#7
|
elite*gold: 0
Join Date: Oct 2013
Posts: 6
Received Thanks: 0
|
Quote:
Originally Posted by mlukac89
Then u need to change all, so what exactly that script need to do ? You can add me on skype ( mario.lukacic.or ) if u have it, or facebook  so i can explain u better.
|
now i add you in facebook
|
|
|
05/06/2016, 08:12
|
#8
|
elite*gold: 1908
Join Date: Jan 2013
Posts: 832
Received Thanks: 629
|
it is not safe to use connection to dbs in script (possibility of decompiling). Use php and then send GET request to some php file(which will echo what u want). And then autoit can read that echo-ed text with:
$TextFromPHP= _INetGetSource("www.page.php")
|
|
|
05/06/2016, 20:37
|
#9
|
elite*gold: 0
Join Date: Sep 2010
Posts: 473
Received Thanks: 104
|
Quote:
Originally Posted by ssamko
it is not safe to use connection to dbs in script (possibility of decompiling). Use php and then send GET request to some php file(which will echo what u want). And then autoit can read that echo-ed text with:
$TextFromPHP= _INetGetSource("www.page.php")
|
Did u see what i wrote ? There is nothing in autoit code on in php script on server, when u access it its like u access over normal webpage so there is no problem.
|
|
|
05/08/2016, 14:22
|
#10
|
elite*gold: 1908
Join Date: Jan 2013
Posts: 832
Received Thanks: 629
|
Quote:
Originally Posted by mlukac89
Did u see what i wrote ? There is nothing in autoit code on in php script on server, when u access it its like u access over normal webpage so there is no problem.
|
sorry...I didnt read your code....I wrote it in general
|
|
|
Similar Threads
|
Autoit How do I connect to MySQL?
05/13/2013 - AutoIt - 3 Replies
Autoit How do I connect to MySQL?
The like of which you do not.
Like this Olympus Team Tutorial - YouTube
Please ask for it.
|
All times are GMT +1. The time now is 19:18.
|
|