gpt4 book ai didi

php - 尝试获取要在发送给用户的电子邮件信息中显示的记录 ID

转载 作者:行者123 更新时间:2023-11-29 12:35:46 25 4
gpt4 key购买 nike

我在这里创建了一个表单,当用户输入所需信息并点击提交时。它将用户带到打印信息并通过电子邮件向他们发送信息的页面。我遇到的问题是当用户提交表单时。我无法获取要在消息中填充的记录 ID。 id是MySQL数据库中的一个自增主键。我该怎么做才能让记录显示出来。

下面是 create.php 代码。允许用户输入数据

<!DOCTYPE html>
<html>

<head>
<title>Systems Request</title>
<script type="text/javascript" src="Javascript/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="Javascript/ShowTextbox.js"></script>
<script type="text/javascript" src="Javascript/textboxname_autocomplete.js"></script>
<script type="text/javascript" src="Javascript/Requiredfields.js"></script>
<link href="css/create.css" rel="stylesheet" type="text/css">
</head>

<body style="background-image: url('../Systems/images/background.jpg')">
<h1 class="h1">Systems Request<br><br></h1>
<div align="center">
<form action="insert_process.php" onsubmit="return formCheck(this);" method="post" class="form" style="width: 624px; height: 681px">
<br>
<br>Lan ID
<br>
<input type="text" style="text-transform:uppercase ;" id="lanId" name="lanId">
<br>Name
<br>
<input type="text" id="name" name="name" onkeydown="return false;">
<?php #start of the department location if you need to add another department copy any option value and change the name to the depart desired. ?>
<br>Department Location
<br>
<select name="department" id="department" style="width: 160px" onchange="showfield(this.options[this.selectedIndex].value)">
<option value="">Please select ...</option>
<option value="OTHER">OTHER</option>
</select>
<br>
<?php #end of the department location ?>
<?php /*start of manager section if you need to add a manager copy the option value and change the name. If you need to change a manager just change the name*/ ?>
<br>Manager
<br>
<select name="manager" id="manager" style="width: 160px">
<option value="">Please select ...</option>
<option value="ADRIAN TORRES">John doe</option>
</select>
<?php # end of manager section ?>
<?php #start of Request Issues ?>
<br>Request Issue
<br>
<select name="request" style="width: 160px" onchange="showfield(this.options[this.selectedIndex].value)">
<option value="">Please select ...</option>
<option value="RESET CASE">RESET CASE</option>
</select>
<br>Describe the issue of your request in the comment box bellow?
<br>Exact Location, Printer Name, etc
<br>
<textarea name="request_comments" style="width: 353px; height: 81px" style="text- transform:uppercase ;"></textarea>
<br>
<br>
<input type="submit" value="Submit Request ">
<br>
<?php #Hidden inputs for Status, tech comments, tech completed, tech completed date ?>
<input type="hidden" name="status" value="RECEIVED">
<input type="hidden" name="comments" value="N0_COMMENTS">
<input type="hidden" name="compUser" value="UNASSIGNED">
<input type="hidden" name="compDt" value="NOT_COMPLETED">
</form>
</div>
</body>

</html>

这是 insert_process.php 代码。

<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "systems_requests";
$dbh = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$stm= $dbh->prepare("INSERT INTO requests(lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt) Values (?,?,?,?,?,?,?,?,?,?,?)");
$stm->bindParam(1, $_POST["lanId"]);
$stm->bindParam(2, $_POST["name"]);
$stm->bindParam(3, $_POST["department"]);
$stm->bindParam(4, $_POST["manager"]);
$stm->bindParam(5, $_POST["request"]);
$stm->bindParam(6, $_POST["request_description"]);
$stm->bindParam(7, $_POST["request_comments"]);
$stm->bindParam(8, $_POST["status"]);
$stm->bindParam(9, $_POST["comments"]);
$stm->bindParam(10, $_POST["compUser"]);
$stm->bindParam(11, $_POST["compDt"]);
$stm->execute();
?>
<?php
$id = "id";
$lanId = "lanId";
$department = "department";
$name = "name";
$manager = "manager";
$request = "request";
$request_description = "request_description";
$request_comments = "request_comments";
$status = "status";
$comments = "comments";
$compUser= "compUser";
$compDt = "compDt";
$to = "test@gmail.com";
$subject = "Systems Request";
$headers = "From: test@gmail.com";
$message ="LanID: " . $lanId . "
" ."User Name: ". $name ."
". "Department: " . $department . "
" ."Manager: ". $manager . "
". "User Request: " . $request . "
" ."User Request Description: ". $request_description . "
" ."User Request comments: ". $request_comments . "
" ."Status: " . $status . "
" ."Systems comments: ". $comments . "
" ."Completed by: ". $compUser ;
mail($to,$subject,$message,$headers);
echo ("<br> <a href='http://a0319p528/dc399Homepage/'> DC399Homepage </a>");
?>
<html>
<body>
<br><br><br>
<h1 align="center">Systems Request Confirmation</h1>
<p align="center">Thank you, <?php echo $_POST["name"]; ?><br><br>
Your request has been sent. Your request number is <?php echo $_POST['id']; ?><br>
Please write this number down or print this page out.</p>
<div align="center">
<h2>Request Information</h2>
Date Request: <?php
$date = new DateTime();
echo $date->format('m/d/Y H:i:s') . "\n";
?><br>
Manager: <?php echo $_POST["manager"]; ?><br>
Location: <?php echo $_POST["department"]; ?><br>
Request Issue: <?php echo $_POST["request"]; ?> <?php echo $_POST["request_description"]; ?><br>
Request Comments: <?php echo $_POST["request_comments"]; ?><br>
</div>
<div align="center">
<h2>Status Information</h2>
Status: <?php echo $_POST["status"]; ?><br><br><br><br>
</div>
<div align="center"><button onClick="window.print()">Print this page</button></div>
</body>
</html>

最佳答案

在 insert_process 页面上

 replaced   <?php  echo $_POST['id']; ?>

with  <?php echo $dbh->lastInsertId();?> 

还删除了 $id="id"

关于php - 尝试获取要在发送给用户的电子邮件信息中显示的记录 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26821525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com