为什么我在电子邮件和数据库中得到两个不同的值?

时间:2019-02-21 00:50:10

标签: php html mysql database forms

因此,我创建了一个表单,其中值存储在数据库中,并且也通过电子邮件发送,到目前为止一切正常。

现在,我创建了一个名为trackingcode的变量,它会生成10个随机字符。我的问题是我在电子邮件中收到的trackingcode与存储在数据库中的电子邮件不同。

这是一个例子,这是我从电子邮件中获得的例子:

Email

这是我在数据库中拥有的内容:

Database

这是我的插入代码:

<?php
//insert.php
$connect = mysqli_connect("localhost", "root", "", "pcrequest");
if(isset($_POST["reqname"]))
{
 $length = 10;
 $trackingcode = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
 $reqname = $_POST["reqname"];
 $date = $_POST["date"];
 $empname = $_POST["empname"];
 $position = $_POST["position"];
 $account = $_POST["account"];
 $platform = $_POST["platform"];
 $processor = $_POST["processor"];
 $ram = $_POST["ram"];
 $monitor = $_POST["monitor"];
 $phone = $_POST["phone"];
 $phonetype = $_POST["phonetype"];
 $headset = $_POST["headset"];
 $approval = $_POST["approval"];
 $status = $_POST["status"];
 $query = '';
 for($count = 0; $count<count($reqname); $count++)
 {
  $trackingcode_clean = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
  $reqname_clean = mysqli_real_escape_string($connect, $reqname[$count]);
  $date_clean = mysqli_real_escape_string($connect, $date[$count]);
  $empname_clean = mysqli_real_escape_string($connect, $empname[$count]);
  $position_clean = mysqli_real_escape_string($connect, $position[$count]);
  $account_clean = mysqli_real_escape_string($connect, $account[$count]);
  $platform_clean = mysqli_real_escape_string($connect, $platform[$count]);
  $processor_clean = mysqli_real_escape_string($connect, $processor[$count]);
  $ram_clean = mysqli_real_escape_string($connect, $ram[$count]);
  $monitor_clean = mysqli_real_escape_string($connect, $monitor[$count]);
  $phone_clean = mysqli_real_escape_string($connect, $phone[$count]);
  $phonetype_clean = mysqli_real_escape_string($connect, $phonetype[$count]);
  $headset_clean = mysqli_real_escape_string($connect, $headset[$count]);
  $approval_clean = mysqli_real_escape_string($connect, $approval[$count]);
  $status_clean = mysqli_real_escape_string($connect, $status[$count]);
  if($trackingcode_clean != '' && $reqname_clean != '' && $date_clean != '' && $empname_clean != '' && $position_clean != '' && $account_clean != '' && $platform_clean != '' && $processor_clean != '' && $ram_clean != '' && $monitor_clean != '' && $phone_clean != '' && $phonetype_clean != '' && $headset_clean != '' && $approval_clean != '' && $status_clean != '')
  {
   $query .= '
   INSERT INTO request(trackingcode, reqname, date, empname, position, account, platform, processor, ram, monitor, phone, phonetype, headset, approval, status) 
   VALUES("'.$trackingcode_clean.'", "'.$reqname_clean.'", "'.$date_clean.'", "'.$empname_clean.'", "'.$position_clean.'", "'.$account_clean.'", "'.$platform_clean.'", "'.$processor_clean.'", "'.$ram_clean.'", "'.$monitor_clean.'", "'.$phone_clean.'", "'.$phonetype_clean.'", "'.$headset_clean.'", "'.$approval_clean.'", "'.$status_clean.'"); 
   ';
  }
 }

for($count = 0; $count<count($reqname); $count++)
 {
$email_from = "PC Request";//<== update the email address
$email_subject = "PC Request for $account_clean";
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';

$message = '<html><body>';
$message .= "<tr><td>Good morning,</td></tr>";
$message .= "<br>";
$message .= "<br>";
$message .= "<tr><td>Here are the specifications:</td></tr>";
$message .= "<br>";
$message .= "<br>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="5">';
$message .= "<tr style='background: #FFFFFF;'><td><strong>Tracking Code</strong> </td><td style='color:blue;'>" . $trackingcode . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Requested by</strong> </td><td>" . $reqname_clean = mysqli_real_escape_string($connect, $reqname[$count]) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Start Date</strong> </td><td>" . $date_clean = mysqli_real_escape_string($connect, $date[$count]) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Employee Name</strong> </td><td>" . $empname_clean = mysqli_real_escape_string($connect, $empname[$count]) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Position</strong> </td><td>" . $position_clean = mysqli_real_escape_string($connect, $position[$count]) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Account</strong> </td><td>" . $account_clean = mysqli_real_escape_string($connect, $account[$count]) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Platform</strong> </td><td>" . $platform_clean = mysqli_real_escape_string($connect, $platform[$count]) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Processor</strong> </td><td>" . $processor_clean = mysqli_real_escape_string($connect, $processor[$count]) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>RAM</strong> </td><td>" . $ram_clean = mysqli_real_escape_string($connect, $ram[$count]) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Monitor</strong> </td><td>" . $monitor_clean = mysqli_real_escape_string($connect, $monitor[$count]) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Phone</strong> </td><td>" . $phone_clean = mysqli_real_escape_string($connect, $phone[$count]) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>Phone Type</strong> </td><td>" . $phonetype_clean = mysqli_real_escape_string($connect, $phonetype[$count]) . "</td></tr>";
$message .= "<tr style='background: #FFFFFF;'><td><strong>Headset</strong> </td><td>" . $headset_clean = mysqli_real_escape_string($connect, $headset[$count]) . "</td></tr>";
$message .= "<tr style='background: #CDD9FF;'><td><strong>View Requests</strong> </td><td><a href='teamspan.com/core/pcrequest/messages-admin.php'>Click Here!</a></td></tr>";
$message .= "</table>";
$message .= "</body></html>";

$to = "renzoandredg@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$message, $headers);
//done. redirect to thank-you page.
//header('Location: index.php');

}

 if($query != '')
 {
  if(mysqli_multi_query($connect, $query))
  {
   echo 'Successfuly Sent!';
  }
  else
  {
   echo 'Error';
  }
 }
 else
 {
  echo 'All fields are required!';
 }
}
?>

1 个答案:

答案 0 :(得分:0)

您在数据库中插入了$trackingcode_clean,但在电子邮件中发送了$trackingcode ...