0

I use the Paypal IPN. When the user buys articles, I use this code to generate codes they can redeem. However, it's not working:

public function clave(){
       $Valores = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
       $ValorTemporal = "";
        for($i=0;$i<10;$i++) {
        $ValorTemporal .= substr($Valores,rand(0,37),1);

        }
        return $ValorTemporal;
    }

    public function cupon($items){
                $mysqli = $this->connection();
            for ($i = 1; $i <= $items; $i++) {
        $yz= $this->clave();
    $sqli.$i = $mysqli->query("INSERT INTO ventas (id_venta, id_usuario,id_producto ,used,cupon) VALUES ('$txn_id','$username','$item_name','$used','$yz')");

    }

            return true;
    }

$items is the number of products I don't know if I'm using the for() statement correctly.

2
  • what is this? $sqli.$i also $txn_id $username $item_name $used are undefined in you cupon function Commented Sep 2, 2015 at 1:57
  • $sql is just an idintifier the others are defined globally Commented Sep 2, 2015 at 2:13

1 Answer 1

1
public function cupon($items){
    global $txn_id, $username, $item_name, $used;

    $mysqli = $this->connection();
    for ($i = 1; $i <= $items; $i++) {
        $yz = $this->clave();
        $mysqli->query("
            INSERT INTO `ventas` 
                (`id_venta`, `id_usuario`, `id_producto`, `used`, `cupon`) 
            VALUES 
                ('$txn_id', '$username', '$item_name', '$used', '$yz')
        ");
    }
    return true;
}

OR little better

public function cupon($items, $txn_id, $username, $item_name, $used){
    $mysqli = $this->connection();
    for ($i = 1; $i <= $items; $i++) {
        $yz = $this->clave();
        $mysqli->query("
            INSERT INTO `ventas` 
                (`id_venta`, `id_usuario`, `id_producto`, `used`, `cupon`) 
            VALUES 
                ('$txn_id', '$username', '$item_name', '$used', '$yz')
        ");
    }
    return true;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.