douchao9899
douchao9899
2014-11-08 20:04

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

已采纳

I have a form here I created that when a user enters the required information and hits submit. It takes the user to a page that prints out the information and emails them the info. The issue I am having is that when user submits form. I am not able to get the id of the record to populate in the message. The id is a primary key with auto increment in the MySQL database. What can I do to get the record to show up.

Here is the create.php code bellow. which allows the user to enter the data

<!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>

Here is the insert_proccess.php code.

<?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') . "
";
    ?><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>

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanleiliu7373 duanleiliu7373 7年前

    On the insert_process page

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

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

    also removed $id="id"

    </div>
    
    点赞 评论 复制链接分享