dimanche 26 novembre 2017

How do i generate a random string and update to database were record is query

Am new here but i dont really no how to explain my question to keep me save from votedown and in achievement am trying to generate random string from the function show_ticket then update to database were record is query example generate string from function show_ticket join them as one line string str_plit them occording to index record output then update it to database i have tried:

<?php
require("init.php");
function show_ticket($length) {
      $str="";
      $chars = "abcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
      $size = strlen($chars);
      for($i = 0;$i < $length;$i++) {
       $str .= $chars[rand(0,$size-1)];
      }
      return $str;
     }
$sql = mysqli_query($conn, "select * from books where book='1644445'");
while($row = mysqli_fetch_assoc($sql))
{
$bid=$row["id"];
$da  = $row["item_name"];  $qty  = $row["quantity"];  $view=$row["seen"];
$sqll = mysqli_query($conn, "SELECT * FROM promo WHERE code='$da' LIMIT 1");
while ($prow = mysqli_fetch_array($sqll))
{
$idd = $prow["id"];
$code = $prow["recharge"];
$price = $prow["price"];

}
$start = preg_split("/$view/", $code);
$result = str_split($start[1], 12);
$cred = 0;
$cred = $price * $qty;
$pid = $cred + $pid;
for ($b = 0; $b<$qty; $b++)
{
$ticket = show_ticket(4);
$play = "price $pid <br/>ticket $ticket <br/>content $result[$b]";
echo $play;
}
}
$qlu = mysqli_query($conn, "select * from books where book='1644445'");$join .= "$ticket";
$show_plit = str_split($join, 4);
$m = 0;
while($roww = mysqli_fetch_assoc($qlu))
{
$tid  = $roww["id"];
$tqty  = $roww["quantity"];
$oldB = $m;
$am = " ";
for(; $m< $oldB + $tqty; $m++)
{
$am .= "$show_plit[$m]";mysqli_query($conn, "UPDATE books SET ticket='$am' WHERE id=$tid");
}
}

but i get no better result what i mine doing wrong. Big thanks in advance




Aucun commentaire:

Enregistrer un commentaire