dongqu9917 2015-11-16 07:19
浏览 38

根据选中的复选框无法在数据库中插入/更新值

I'm working with send mail function of my page. To be able to get the values in the table I want to add a checkbox in each row that can tick more than 1 rows. Then once submitted by a button, it will be inserted in the database. I don't know what's wrong with my code.

No error is displaying. But Record is successfully updated! is displayed when I click save button. I forgot to include, I have 2 textboxes and 1 dropdown. I just want to insert and update theses data on the database.

Here's the 2 textboxes and the dropdown list:

<table name=container border=1 align=center>
<td>
<table class='formtb' style='font-size:0.6em;'>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td>Person in Charge: </td>
<td><textarea rows='4' cols='40' name="pic" value="<?php echo $row2['PersoninCharge']?>" placeholder="Email address only. Use comma(,) for multiple email address."></textarea></td>
<td>&nbsp;</td>
<td></td>
</tr>

<tr>
<td>PIC Comments: </td>
<td><textarea rows='4' cols='40' name='comt' value="<?php echo $row2['PIC_Comments']?>"></textarea></td>
<td>&nbsp;</td>
<td></td>
</tr>

<tr>
<td>Status: </td>
<td><select name="stat">
<option value="">&nbsp;</option>";
<option value="Open" <?php if($row2['Status']=="Open") echo selected;?>> Open </option>
<option value="Closed" <?php if($row2['Status']=="Closed") echo selected;?>> Closed </option>
 </select>&nbsp;&nbsp;</td>
<td></td>
<td></td>
</tr>

<tr>
<td>&nbsp;</td>
<td><input type='submit' name='save_btn' value='&diams; SAVE &diams;' style='font-size:1.5em;'/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td></td>
<td></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

</table>
</td>
</table>

Here's the table fetched from the database:

<table class ='tb2' border=20 style='font-size:0.6em;' id='result'>
<tr>
<th> </th>
<th>ISSUE TYPE</th>
<th>CREATION DATE</th>
<th>SITE</th>
<th>VENDOR NAME</th>
<th>INVOICE DATE</th>
<th>INVOICE NUMBER</th>
<th>PART NUMBER</th>
<th>PO</th>
<th>RR</th>
<th>CURRENCY</th>
<th>INVOICE AMOUNT</th>
<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ISSUES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
<!--<th>PERSON IN CHARGE</th>
<th>PIC COMMENTS</th>
<th>STATUS</th>-->
</tr>

<?php 

$invtxt = $_POST['InvNumbTxt'];
$conn=dbConnect();         
$sql="SELECT * FROM invalid_invoice";
$stmt=$conn->prepare($sql); 
$stmt->execute();

if(!isset($_POST['search_btn'])) {
while($row =$stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<form name='update' method='POST' autocomplete='off'>"; 
echo "<tr class=output2>";
echo "<td><input type='checkbox' name='checkb[]' value='".$row['ID']."'></td>";
echo "<td>".$row['Issue_Type']."</td>";
echo "<td>".$row['Creation_Date']."</td>";
echo "<td>".$row['Site']."</td>";
echo "<td>".$row['Vendor_Name']."</td>";
echo "<td>".$row['Invoice_Date']."</td>";
echo "<td>".$row['Invoice_Number']."</td>";
echo "<td>".$row['Part_Number']."</td>";
echo "<td>".$row['PO']."</td>";
echo "<td>".$row['RR']."</td>";
echo "<td>".$row['Currency']."</td>";
echo "<td>".$row['Invoice_Amount']."</td>";
echo "<td>".$row['Issues']."</td>";
 echo "</tr>";
 echo "</form>"; 
 }
 } 
 $conn=null;
</table>

Here's the save button:

if(isset($_POST['save_btn'])) {

/*if(empty($_POST['checkb[]'])) {
echo "<script language='javascript'>alert('No data saved!')</script>";}

else*/ if(empty($_POST['stat'])){
echo "<script language='javascript'>alert('No data saved!')</script>"; }

else if (!filter_var($pic, FILTER_VALIDATE_EMAIL)) {
echo "<script language='javascript'>alert('Invalid email format. Please re-enter valid email only!')</script>"; }

else {    
try {

$concat = implode(",",$_POST['checkb']);
$deconcat = explode(",",$concat);
foreach($deconcat as $ndeconcat)
{

$sql2="UPDATE invalid_invoice SET 
            UpdateBy =:updateby, 
            UpdateDateTime=NOW(),
            PersoninCharge=:pic,
            PIC_Comments=:comt,
            Status=:stat 
        WHERE ID =:id";
$conn=dbConnect();
$stmt2=$conn->prepare($sql2);
$stmt2->bindParam(':updateby', $_SESSION['login_user'], PDO::PARAM_STR);
$stmt2->bindParam(':pic', $_POST['pic'], PDO::PARAM_STR);
$stmt2->bindParam(':comt', $_POST['comt'], PDO::PARAM_STR);
$stmt2->bindParam(':stat', $_POST['stat'], PDO::PARAM_STR);
$stmt2->bindParam(':id', $_POST['idtxt'], PDO::PARAM_INT);
$stmt2->execute();

//echo a message to say the UPDATE succeeded
echo $stmt2->rowCount() . " records UPDATED successfully";

$mess2=$stmt2->execute();   
if($mess2) {
echo "<script language='javascript'>alert('Record is successfully updated!')</script>";
echo "<meta http-equiv='REFRESH' content='0;url='ap.Invalid.Invoice.Tracking.php'>";
}
else {
echo "<script language='javascript'>alert('Unable to update record. Please try again!')</script>";
}   
$conn = null;

//Insert Email:

$sql6 = "SELECT * FROM invalid_invoice WHERE ID=:id6";
$conn = dbConnect();
$stmt6 = $conn->prepare($sql6); 
$stmt6->bindParam(':id6', $_POST['idtxt'], PDO::PARAM_INT);
$stmt6->execute();
$data = $stmt6->fetchAll(PDO::FETCH_ASSOC);    
$conn=null;


foreach ($data as $row6) {

$invnumb=$row6['Invoice_Number'];
$partnumb=$row6['Part_Number'];
$issue=$row6['Issues'];
$pic=$row6['PIC_Comments'];
$emailadd= $row6['PersoninCharge'];
$issuetype=$row6['Issue_Type'];
$createdate=$row6['Creation_Date'];
$site=$row6['Site'];
$vendor=$row6['Vendor_Name'];
$invdate=$row6['Invoice_Date'];
$po=$row6['PO'];
$rr=$row6['RR']; 
$currency=$row6['Currency'];
$invamount=$row6['Invoice_Amount'];
$stat=$row6['Status'];


if($row6['Status']=="Open") {

$message = "<html><b>Issue Type: {$issuetype} </b><br><br>";       
$message .= "<b>Creation Date: {$createdate} </b><br><br>";
$message .= "<b>Site: {$site} </b><br><br>";
$message .= "<b>Vendor Name: {$vendor} </b><br><br>";
$message .= "<b>Invoice Date: {$invdate} </b><br><br>";
$message .= "<b>Invoice Number: {$invnumb} </b><br><br>";
$message .= "<b>Part Number:</b><br>{$partnumb}<br><br>";
$message .= "<b>PO: {$po} </b><br><br>";
$message .= "<b>RR: {$rr} </b><br><br>";
$message .= "<b>Currency: {$currency} </b><br><br>";
$message .= "<b>Invoice Amount: {$invamount} </b><br><br>";
$message .= "<b>Issues:</b><br>{$issue}<br>";
$message .= "<b>Status: {$stat} </b><br><br>";  
$message .= "<b>{$pic}<b><br>";  
$message .= "</html>";


if(!empty($emailadd)) {

dbInsertEmailMessage($emailadd, "Invoice Number: {$invnumb} - {$issue}.", $message); echo "alert('Email sent to {$emailadd}')"; }

}
} 

} 

function dbInsertEmailMessage($send_to, $subject, $message) {

$sql7 = "INSERT INTO email_queue (send_to, subject, message) VALUES (:send_to, :subject, :message)";    
$conn = dbConnect();
$stmt7 = $conn->prepare($sql7); 
$stmt7->bindParam(':send_to', $send_to);
$stmt7->bindParam(':subject', $subject);
$stmt7->bindParam(':message', $message);
$stmt7->execute();
$conn=null; 
}
}           
}
catch(PDOException $e) {
echo $e->getMessage();
}
}
}
?>

I've tried to use this, but it didn't work. (Actually I don't know how it works.)

$(document).ready(function() {
    $("input[name='checkb[]']").click(function() {
            var output = "";
            $("input:checked").each(function() {
                output += $(this).val() + ",";
            });                 
    $("input[name='idtxt']").val(output.trim());                    
            });
    });
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题