0

我有一个发送两个变量的 html 表单,如下所示:

tablegen.php

 <?php
include 'email.php';
function connect(){

    mysql_connect("localhost","root","asda") or die ('Error Reaching Database');
    mysql_select_db("MathGuide");


}   
    //Area  51, idk what I'm doing

function tableGen($x) {
$term=$x;
$sql = mysql_query("select * from student_info where ID like '$term'");
$output = "";
$output .= "<h1>STUDENT DATA for ID: $term</h1>";
$output .=  "<table>";
$output .=  "<tr>
<th>ID</th>
<th>Project</th>
<th>Starter Project</th>
<th>Course</th>
<th>KDs Completed in your Course</th>
<th>Projects Completed</th>
<th>Project 1</th>
<th>P1KD1</th>
<th>P1KD2</th>
<th>P1KD3</th>
<th>P1KD4</th>
<th>P1KD5</th>
<th>Project 2</th>
<th>P2KD1</th>
<th>P2KD2</th>
<th>P2KD3</th>
<th>P2KD4</th>
<th>P2KD5</th>
<th>Project 3</th>
<th>P3KD1</th>
<th>P3KD2</th>
<th>P3KD3</th>
<th>P3KD4</th>
<th>P3KD5</th>
<th>Project 4</th>
<th>P4KD1</th>
<th>P4KD2</th>
<th>P4KD3</th>
<th>P4KD4</th>
<th>P4KD5</th>
</tr>";

while ($row = mysql_fetch_array($sql))
{
$output .=  "<tr><td>";
$output .=  $row['ID'];
$output .=  "</td><td>";
$output .=  $row['Project'];
$output .=  "</td><td>";
$output .=  $row['Starter Project'];
$output .=  "</td><td>";
$output .=  $row['Course'];
$output .=  "</td><td>";
$output .=  $row['KDs completed in your course'];
$output .=  "</td><td>";
$output .=  $row['Projects Completed'];
$output .=  "</td><td>";
$output .=  $row['Project 1'];
$output .=  "</td><td>";
$output .=  $row['P 1 KD 1'];
$output .=  "</td><td>";
$output .=  $row['P 1 KD 2'];
$output .=  "</td><td>";
$output .=  $row['P 1 KD 3'];
$output .=  "</td><td>";
$output .=  $row['P 1 KD 4'];
$output .=  "</td><td>";
$output .=  $row['P 1 KD 5'];
$output .=  "</td><td>";
$output .=  $row['Project 2'];
$output .=  "</td><td>";
$output .=  $row['P 2 KD 1'];
$output .=  "</td><td>";
$output .=  $row['P 2 KD 2'];
$output .=  "</td><td>";
$output .=  $row['P 2 KD 3'];
$output .=  "</td><td>";
$output .=  $row['P 2 KD 4'];
$output .=  "</td><td>";
$output .=  $row['P 2 KD 5'];
$output .=  "</td><td>";
$output .=  $row['Project 3'];
$output .=  "</td><td>";
$output .=  $row['P 3 KD 1'];
$output .=  "</td><td>";
$output .=  $row['P 3 KD 2'];
$output .=  "</td><td>";
$output .=  $row['P 3 KD 3'];
$output .=  "</td><td>";
$output .=  $row['P 3 KD 4'];
$output .=  "</td><td>";
$output .=  $row['P 3 KD 5'];
$output .=  "</td><td>";
$output .=  $row['Project 4'];
$output .=  "</td><td>";
$output .=  $row['P 4 KD 1'];
$output .=  "</td><td>";
$output .=  $row['P 4 KD 2'];
$output .=  "</td><td>";
$output .=  $row['P 4 KD 3'];
$output .=  "</td><td>";
$output .=  $row['P 4 KD 4'];
$output .=  "</td><td>";
$output .=  $row['P 4 KD 5'];
$output .=  "</td></tr>";

}
$output .=  "</table>";
echo $output;
echo "<form action='email.php?check&;' method = 'post'>";
echo "<p><b>Do you want this in an email?</b></p>";
echo "<input type='text' name='send'/>";
echo "<input type='hidden' name='output' value='$output'/>";
echo "<input type='submit' name='submit' value='Send!' />";
echo "</form>";


}
error_reporting(-1); // display all faires
ini_set('display_errors', 1);  // ensure that faires will be seen
ini_set('display_startup_errors', 1); // display faires that didn't born

?>

电子邮件.php

   <html>
<head>
<style>
body {
background-color:#1C2932;
}
p {
font-family: Helvetica;
font-size: 18px;
color: #989898;
}

</style>
</head>
<body>
<?php

if (isset($_GET['check'])) {
$email = $_GET['check'];
$message = $_POST['output'];
$headers = array(
'From: summitmathguide@gmail.com',
'Content-Type: text/html',
'Content-Type: text/css',
);
mail($email,'HTML Email',$message,implode("\r\n",$headers));
echo "<p>Email Sent!</p>";
error_reporting(-1); // display all faires
ini_set('display_errors', 1);  // ensure that faires will be seen
ini_set('display_startup_errors', 1); // display faires that didn't born

}
?>
</body>
</html>

变量emailpostssend因为那是文本框的名称。如何设置变量等于$output

以上是tablegen.php 和email.php 的代码。

非常感谢您的帮助?

4

3 回答 3

0

带有隐藏输入

 $escaped_output = htmlspecialchars($output, ENT_HTML5 | ENT_QUOTES);
 echo "<form action='email.php' method = 'post'>";
 echo "<p><b>Do you want this in an email?</b></p>";
 echo "<input type='text' name='check'/>";
 echo "<input type='hidden' name='output' value='$escaped_output'/>";// hidden input
 echo "<input type='submit' name='submit' value='Send!' />";
 echo "</form>";

并把if(isset($_POST['check'])) {而不是if(isset($_GET['check'])) {

<?php
if(isset($_POST['check'])) {
   $email = $_POST['check'];
   $message = $_POST['output'];
   $headers = array(
               'From: summitmathguide@gmail.com',
               'Content-Type: text/html',
               'Content-Type: text/css',
           );
   mail($email,'HTML Email',$message,implode("\r\n",$headers));
   echo "<p>Email Sent!</p>";
   error_reporting(-1); // display all faires
   ini_set('display_errors', 1);  // ensure that faires will be seen
   ini_set('display_startup_errors', 1); // display faires that didn't born

}
?>
于 2013-05-01T05:00:32.893 回答
0

是的,您可以使用隐藏字段

 echo "<form action='email.php?check&;' method = 'get'>";
 echo "<p><b>Do you want this in an email?</b></p>";
 echo "<input type='text' name='send'>";
 echo "<input type='hidden' name='output' value='$output'>";// hidden input
 echo "<input type='submit' name='submit' value='Send!' />";
 echo "</form>";
于 2013-05-01T05:01:35.963 回答
0

一种方法:在表单中添加隐藏字段

<!-- ignore that backslash -->
echo "<input type='hidden' name='output' value='$escaped_output' />";

(其中$escaped_output = htmlspecialchars($output, ENT_HTML5 | ENT_QUOTES);),然后检索该值:

$message = $_POST['output'];
// $message now contains last page's $output
于 2013-05-01T05:03:45.603 回答