how to insert split string to mysql database using php -
how insert string split data database using php
$client=split("\|", $input); $n = trim($input); // insert mysql $output = "ok ... $client[0] $client[1] $client[2] $client[3]";
check above code , let ideas how insert output database related fileds. using below code...
/ loop through array $number = count($items); ($i=0; $i<=$number; $i++) { // store single item number , quantity in local variables $itno = $items[$i]; $quant = $quantities[$i]; if ($items[$i] <> '') { mysql_query('insert reservation_items (reservationid,productid,productquantity) values($thereservationid,$itno,$quant)'); } }
this have tried..
$bill_no = $client[0]; $bill_amount = $client[1]; $item_name = $client[2]; $quantity = $client[3]; $rate = $client[4]; $amount = $client[5]; $discount = $client[6]; $query = mysql_query("insert billing (bill_no, bill_amount, item_name, quantity, rate, amount, discount) values ('$client[0]', '$client[1]', '$client[2]', '$client[3]', '$client[4]', '$client[5]', '$client[6]')");
so, first of all, please go mysql_* functions (which deprecated, not supported anymore , can cause security issues) pdo or mysqli (http://php.net/pdo , http://php.net/mysqli)
now, considering problem there, did of job.
first of all, retrieve pieces of information provided , split them preg_split or explode (preg_split needs regular expressions first parameter while explode not).
$client=preg_split("\|", $input);
then last part (in case not have 7 parts of string, error) :
$bill_no = $client[0]; $bill_amount = $client[1]; $item_name = $client[2]; $quantity = $client[3]; $rate = $client[4]; $amount = $client[5]; $discount = $client[6];
then last part
$req = $pdo->prepare("insert billing (bill_no, bill_amount, item_name, quantity, rate, amount, discount) values (:bill_no, :bill_amount, :item_name, :quantity, :rate, :amount, :discount)"); $req->execute(array( "bill_no" => $bill_no, "bill_amount" => $bill_amount, "item_name" => $item_name, "quantity" => $quantity, "rate" => $rate, "amount" => $amount, "discount" => $discount ));
but explain bit $items
variable in 2nd part please ? way able fullfy answer
Comments
Post a Comment