Connect autoit to sql

05/03/2016 04:20 jojo6262#1
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?


I want to transfer $input in autoit to check email in database but i can't understand how to do that.


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 mlukac89#2
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
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
05/03/2016 22:40 elmarcia#3
Local $url = "http://yoursite/login.php?email=[Only registered and activated users can see links. Click Here To Register...] or 1==1 will work
05/03/2016 23:40 mlukac89#4
On what u mean on php code ? u dont see its protected ? :D
05/04/2016 03:01 jojo6262#5
Quote:
Originally Posted by mlukac89 View Post
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
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
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 [Only registered and activated users can see links. Click Here To Register...]
05/04/2016 17:40 mlukac89#6
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 [Only registered and activated users can see links. Click Here To Register...] so i can explain u better.
05/04/2016 20:08 jojo6262#7
Quote:
Originally Posted by mlukac89 View Post
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 [Only registered and activated users can see links. Click Here To Register...] so i can explain u better.
now i add you in facebook
05/06/2016 08:12 ssamko#8
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 mlukac89#9
Quote:
Originally Posted by ssamko View Post
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 ssamko#10
Quote:
Originally Posted by mlukac89 View Post
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 :D