SQL Enregistrement sur 2 ligne au lieu d'une.

    Publicités

Users Who Are Viewing This Thread (Total: 0, Members: 0, Guests: 0)

#Dudule100

Membre
Apr 6, 2014
40
0
126
Rebonjour,

Bon alors voila les Screenshots vont parler pour moi :
g5es.png


Je voudrais que sa soit sur la meme ligne. Voila mon scripte php pour généré la licence :
PHP:
<?php
//http://shockdevs.esy.es/IPN.php?token=9K008656V4952294L&amt=0.01&cc=EUR&item_name=test&item_number=2&st=Completed&tx=7DM49960EB049253M

$token = $_GET['token'];
$amt = $_GET['amt'];
$cc = $_GET['cc'];
$item_name = $_GET['item_name'];
$item_number = $_GET['item_number'];
$st = $_GET['st'];
$tx = $_GET['tx'];

echo $token;
echo $amt;
echo $cc;
echo $item_name;
echo $item_number;
echo $st;
echo $tx;

if ($st == "Completed")
{
    try
    {
        $db = new PDO('mysql:host=localhost;dbname=name', 'user', 'pass'); //Connexion base de donnée en PDO 
        $db->exec("SET NAMES 'UTF8'");
    }
    catch (PDOException $e)
    {
        echo $e->getMessage();
    }
	
    if ($amt == "0.01")
    {
        $date = time() + 2592000; //3 mois
        $rqt = $db->prepare('INSERT INTO Registerkeys(Registerkey, Expirationdate) VALUES(:Registerkey, :Expirationdate)');
        $rqt->bindValue('Registerkey', $token);
        $rqt->bindValue('Expirationdate', $date);
        $rqt->execute();
        $rqt = $db->prepare('INSERT INTO Users(Expirationdate) VALUES(:Expirationdate)');
        $rqt->bindValue('Expirationdate', $date);
        $rqt->execute();
        header('Location: licensebuy.php?type=3 month&key=' . $token);
    }
    else if ($amt == "0.02")
    {
        $date = time() + 5184000; // 6 mois
        $rqt = $db->prepare('INSERT INTO Registerkeys(Registerkey, Expirationdate) VALUES(:Registerkey, :Expirationdate)');
        $rqt->bindValue('Registerkey', $token);
        $rqt->bindValue('Expirationdate', $date);
        $rqt->execute();
        $rqt = $db->prepare('INSERT INTO Users(Expirationdate) VALUES(:Expirationdate)');
        $rqt->bindValue('Expirationdate', $date);
        $rqt->execute();
        header('Location: licensebuy.php?type=6 month&key=' . $token);
    }
    else if ($amt == "0.03")
    {
        $date = time() + 103680000; // 10 ans
        $rqt = $db->prepare('INSERT INTO Registerkeys(Registerkey, Expirationdate) VALUES(:Registerkey, :Expirationdate)');
        $rqt->bindValue('Registerkey', $token);
        $rqt->bindValue('Expirationdate', $date);
        $rqt->execute();
        $rqt = $db->prepare('INSERT INTO Users(Expirationdate) VALUES(:Expirationdate)');
        $rqt->bindValue('Expirationdate', $date);
        $rqt->execute();
        header('Location: licensebuy.php?type=Lifetime&key=' . $token);
    }

}

?>

Et voici mon scripte pour validé l'enregistrement :
PHP:
<?php

$sessionID = $_GET ["sessionID"];
$actionget = $_GET ["action"];
$hwid = $_GET ["hwid"];
$mac = $_GET ["mac"];
$registerkey = $_GET ["registerkey"];

if (empty($sessionID)) die ("ERROR:INVALID_SESSION_ID");

$action = new action;
if ($actionget == "connect")
 $response = $action->connect($hwid, $mac);
elseif ($actionget == "register")
 $response = $action->register($hwid, $mac, $registerkey);
 else
  $response = "NO_ACTION";
 
echo rc4($sessionID, $response);

class action
{
 public $bdd;
 public function action()
 {
 try {$this->bdd = new PDO('mysql:host=localhost;dbname=u124946711_name', 'u124946711_user', 'Jojolila44'); }
 catch (Exception $ex) {die('ERROR:ERROR_BDD_CONNECTION');}
 }

  public function connect ($hwid, $mac)
 {
  if (!$this->hwidExist($hwid)) return ('ERROR:HWID_NOT_FOUND');
  
  $data = $this->Query("SELECT * FROM Users WHERE Hwid = ?;", array($hwid));
  if ($data['Mac'] != hash ("sha256",($mac)))
   return ('ERROR:INCORRECT_MAC');
  elseif ($data['Banned'] == 1)
   return ("ERROR:HWID_BANNED");
  else
   return ("OK") . $data="0";
 }
 
 public function register ($hwid, $mac, $registerKey)
 
 {
  $data = $this->Query("SELECT * FROM Registerkeys WHERE Registerkey = ?;", array($registerKey));
  if (empty($data['Registerkey'])) return ("ERROR:INVALID_KEY");
  if (!empty($data['Hwid'])) return ("ERROR:KEY_IS_ALREADY_USED");
  if ($this->hwidExist($hwid)) return ("ERROR:HWID_IS_ALREADY_EXIST");
 
 $this->Query("INSERT INTO Users (ID, Hwid, Mac, Banned, Registrationdate) VALUES ('', ?, ?, '0', ?);", array($hwid, hash("sha256",($mac)), getTime()));
 $this->Query("UPDATE Registerkeys SET Hwid = ? WHERE Registerkey = ?;", array($hwid, $registerKey));
 return ("OK:REGISTERED");
 } 
 
 
 private function hwidExist($hwid)
 {
  $data = $this->Query("SELECT * FROM Users WHERE Hwid = ?;", array($hwid));
  if (empty($data['Hwid']))
   return (false);
  else
   return (true);
 }
 
 private function Query($query, $args, $fetch = true)
{
 $response = $this->bdd->prepare($query);
 $response->execute($args);
 if ($fetch)
 {
  $data = $response->fetch();
  $response->closeCursor();
  return ($data);
 }
}

}

function rc4($key, $str) {
$s = array();
for ($i = 0; $i < 256; $i++) {
$s[$i] = $i;
}

$j = 0;

for ($i = 0; $i < 256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
}

$i = 0;
$j = 0;
$res = '';

for ($y = 0; $y < strlen($str); $y++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
$res .= $str[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}

return $res;
}

 function getTime()
 
 {
  date_default_timezone_set('Europe/Paris');
  return date ("Y-m-d H");
 }

?>

Merci de votre aide, c'est cool de votre part.
 

Evaelis

La Voix de la Sagesse
V
Ancien staff
Apr 28, 2010
22,949
468
1,699
Valhalla
Faudrait reflechir et lire la documentation au moins de
INSERT
UPDATE
SELECT
INSERT INTO Users(Expirationdate) VALUES(:Expirationdate)

J'ai meme pas besoin d'aller plus loin je suppose.
 

#Dudule100

Membre
Apr 6, 2014
40
0
126
Faudrait reflechir et lire la documentation au moins de

INSERT INTO Users(Expirationdate) VALUES(:Expirationdate)

J'ai meme pas besoin d'aller plus loin je suppose.

Donc cette ligne :
PHP:
 $this->Query("INSERT INTO Users (ID, Hwid, Mac, Banned, Registrationdate) VALUES ('', ?, ?, '0', ?);", array($hwid, hash("sha256",($mac)), getTime()));

faut que je la transforme en :
PHP:
 $this->Query("UPDATE Users (ID, Hwid, Mac, Banned, Registrationdate) VALUES ('', ?, ?, '0', ?);", array($hwid, hash("sha256",($mac)), getTime()));

Merci en tout cas

Ce que j'ai oublier de précisé, c'est que c'est le scripte qui est mis en premier qui est exécuter avant l'autre. L'autre s’exécute quand l'utilisateur entre la serial généré. Donc si je fait un update dans le 1er scripte, il va me sortir une erreur car la ligne n'existe pas.
 
Last edited: