for循环未在php

时间:2018-12-10 07:50:59

标签: php mysqli

在给定的代码下面,insert仅显示并插入第一条记录,但不显示并插入多条记录。但是,如果我删除插入查询,它将显示多个记录。

感觉在for循环内插入查询有问题。帮我解决问题。

尝试了许多方法,但没有用。

<!-- language: lang-php -->
<?php
include 'connection.php';
 $date=date('d-m-Y');
if ($stmt = $conn->prepare("SELECT id,name,amount,interest,date1,planname FROM investment")) {
    $stmt->bind_param("ssssss", $id1,$name,$amount,$interest,$date1,$planname);
    $stmt->execute();
    $stmt->bind_result($id1,$name,$amount,$interest,$date1,$planname); 
    while ($stmt->fetch())   
    { 
     $rows = mysql_num_rows($stmt);    
    for ($j = 0 ; $j <= $rows; $j++)
    {    
     if ($date1==$date)
     {
      $pay = ($amount * $interest);
        $status='due';
        $month='1';
        echo $name;
        echo $id1;
        echo $planname;
        echo $amount;
        echo $interest;
        echo $month;
        echo $date;
        echo $pay;
        echo $status;
 ?>
<?php       
include 'connection.php';   
$stmt1 = $conn->prepare("INSERT INTO interest(name,investmentid,investmentname,investmentamount,interest,month,date,interestamount,status) VALUES (?,?,?,?,?,?,?,?,?)");
$stmt1->bind_param("sssssssss",$name,$id1,$planname,$amount,$interest,$month,$date,$pay,$status);
$stmt1->execute();
$result=mysql_query($stmt1);
$stmt1->close();
?>
<b><p style="color:red;text-align:center;">
<?php echo " Successfully !!!";?>       
<br /><?php
}
    $j=$j+1;
 }
}
}?>

0 个答案:

没有答案