1

每当我在我的 PHP 脚本中包含某个文件时,它都会破坏代码并仅加载样式表。我不确定是什么导致了这个问题。是依赖引起的吗?我不确定 PHP 是否继承了值等。

search.php 调用 tablegen.php 中的函数。

include 'tablegen.php';

tablegen.php 创建一个变量并返回它。

现在,我想将此变量传递给 email.php 中的函数。但是,当我这样做时:

include 'email.php';

这会破坏“tablegen.php”中的 php 脚本,并且只会加载一个带有背景的空白页面。

感谢您对此问题的任何见解。

完整的 search.php 文件。

       <html>
<head>
<style type="text/css">
table {
background-color: #C0C0C0;
}

th{
width: 150px;
text-align:center;
border-style: solid;
border-width: 2px;
border-color: black;
background-color: #008080;
font-family: Helvetica;
}
td {
border-style: solid;
border-width: 2px;
border-color: black;
font-family: Helvetica;
background-color: #FFFF00;
text-align:center;
}
body {
background-color:#1C2932;
}

h1 {
font-family: Helvetica;
font-size: 24px;
color: #989898;
}

p {
font-family: Helvetica;
font-size: 18px;
color: #989898;
}

</style>
</head>
<body>

<?php
include 'tablegen.php';
include 'email.php';
if (empty($_POST['term'])) {
header("location:landing.php");
}
if(isset ($_POST['term'])) {
$x = $_POST['term'];
     connect();
     $result=tableGen($x);

}//end main if



echo "<form action='search.php' method = 'post'>";
echo "<p><b>Do you want this in an email?</b></p>";
echo "<input type='text' name='send'>";
echo "<input type='submit' name='submit' value='Send!' />";
echo "</form>";
if(isset($_POST['send'])) {
sendEmail($result);
}

?>
<br></br>
<form method="LINK" action="landing.php">
<input type="submit" value="Go Back!">
</form>

</body>
</html>

完整的 tablegen.php 文件

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

    mysql_connect("localhost","root","water123") 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>";
sendEmail($output);
echo $output;
return $output;


}
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

?>

完整的 email.php 文件:

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

</style>
</head>
 <body>
<?php
function sendEmail($table){
$email = $_POST['send'];
$headers = array(
'From: summitmathguide@gmail.com',
'Content-Type: text/html',
'Content-Type: text/css'
);
$content = $table;

mail($email,'HTML Email',$content,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>
4

2 回答 2

2

由 引起的,Evil Faires也称为Exceptions和。它们是不可见的(所以你看不到,是的,看不到!!!),你需要使用一些神奇的环境才能看到这些妖精,所以:WarningsFatal Errors

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-04-30T16:43:28.580 回答
0

此答案与针对“我没有拖延”而发布的评论有关,而不是与当前问题中的代码有关(当您对代码有疑问时,您应该发布包含该问题的版本)。

$outputtableGen()函数内部的局部变量。你不能在函数之外访问它(除非你用 声明它global,但在这种情况下没有理由这样做)。该函数以:

return $output

这意味着您可以将函数调用的结果分配给 in 中的变量search.php,例如

$result = tableGen($x);
sendEmail($output);

这些都与 using 无关,include如果所有函数都在主search.php文件中,您将遇到同样的问题。变量范围基于类和函数,而不是文件。

于 2013-04-30T18:20:33.007 回答