我正在使用我的页面的发送邮件功能。为了能够获取表中的值,我想在每行中添加一个可以勾选超过1行的复选框。然后,一旦按钮提交,它将被插入数据库中。我不知道我的代码有什么问题。
没有显示错误。但记录已成功更新!单击保存按钮时会显示。我忘了包含,我有2个文本框和1个下拉列表。我只想在数据库中插入和更新这些数据。
这是2个文本框和下拉列表:
<table name=container border=1 align=center>
<td>
<table class='formtb' style='font-size:0.6em;'>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </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> </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> </td>
<td></td>
</tr>
<tr>
<td>Status: </td>
<td><select name="stat">
<option value=""> </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> </td>
<td></td>
<td></td>
</tr>
<tr>
<td> </td>
<td><input type='submit' name='save_btn' value='♦ SAVE ♦' style='font-size:1.5em;'/></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td></td>
<td> </td>
<td> </td>
</tr>
</table>
</td>
</table>
这是从数据库中提取的表格:
<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> ISSUES </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>
这是保存按钮:
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;
//插入电子邮件:
$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,“发票编号:{$ invnumb} - {$ issue}。”,$ message); echo“alert('发送到{$ 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();
}
}
}
?>
我试过用它,但它不起作用。 (实际上我不知道它是如何工作的。)
$(document).ready(function() {
$("input[name='checkb[]']").click(function() {
var output = "";
$("input:checked").each(function() {
output += $(this).val() + ",";
});
$("input[name='idtxt']").val(output.trim());
});
});