Skip to content

Instantly share code, notes, and snippets.

@levymoreira
Created April 11, 2014 12:03
Show Gist options
  • Save levymoreira/10462576 to your computer and use it in GitHub Desktop.
Save levymoreira/10462576 to your computer and use it in GitHub Desktop.
Simple php page to receive every month the use confirmation of the program
<?php
//params send by get to page
$companieId = $_GET["id"];
$companieName = $_GET["name"];
//default return
$return = "error";
//database configs
$username = "root";
$password = "root";
$hostname = "locahost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("companies_database",$dbhandle) or die("Could not select database");
//execute the SQL query and return count
$result = mysql_query("SELECT count(*) as cnt FROM companies c where DATE_FORMAT(c.date, '%m%Y') = DATE_FORMAT(now(), '%m%Y') and c.id = " . $companieId) ;
//if does not exist ...
$row = mysql_fetch_array($result);
if($row{'cnt'} == 0 ){
//save new record
$resultInsert = mysql_query("INSERT INTO companies (id, name, date) VALUES ('" .$companieId. "', '" .$companieName. "', now())");
$return = "ok";
}else{
//return ok
$return = "ok";
}
//close the connection
mysql_close($dbhandle);
//return ok or error
echo $return;
?>
/**
Database contain a table called companies with
id (varchar) // to receive cnpj
name (varchar) // name of companie
date (timestamp) // date and time of receivement
Sample delphi use:
// import IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdGlobal, ShellAPI, msxml
function TUtil.EnviarEmpresaWS(const CNPJ: string; const NomeFantasia: string):Boolean;
var
httpRequest: IXMLHttpRequest;
oDataServiceURI: String;
oDataFilter: String;
xmlResults: String;
begin
result := false;
try
oDataServiceURI := 'http://localhost/ws.php';
oDataFilter := '?id='+CNPj+'&name='+NomeFantasia;
httpRequest := CoXMLHTTP.Create;
httpRequest.open('GET', UTF8Encode(oDataServiceURI + oDataFilter), false, EmptyParam, EmptyParam);
httpRequest.send(EmptyParam);
xmlResults := httpRequest.responseText;
if(trim(xmlResults)='ok')then
result := true;
except
end;
end;
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment