我使用的代碼在不同的計算機上工作正常,我現在正在輸出文本格式的代碼,就像它是一個.txt文檔。Php錯誤 - 只顯示文本格式的代碼
這裏是一些受影響的頁面。
connect.php
<?php
$con=mysqli_connect("hr-computing","student","codd","brodie");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
events.php
<?php
$deets = $_POST['deets'];
$deets = preg_replace('#[^0-9/]#i', '', $deets);
include ("connect.php");
$events = '';
$query = mysql_query('SELECT description FROM events WHERE evdate ="'.$deets.'"');
$num_rows= mysql_num_rows($query);
if ($num_rows > 0) {
$events.= '<div id="eventsControl"><button onMouseDown="overlay()">Close</button><br /><b> ' . $deets . '</b><br /><br /></div>';
while($row= mysql_fetch_array($query)) {
$desc = $row['description'];
$events .='<div id="eventsBody">'.$desc .'<br /><hr><br /></div>';
}
}
echo $events;
?>
calendar_start.php
<?php
$showmonth = $_POST['showmonth'];
$showyear = $_POST['showyear'];
$showmonth= preg_replace('#[^0-9]#i', '', $showmonth);
$showyear= preg_replace('#[^0-9]#i', '', $showyear);
$day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear);
$pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear));
$post_days = (6-(date('w', mktime(0,0,0, $showmonth, $day_count, $showyear))));
echo '<div id="calendar_wrap">';
echo '<div class="title_bar">';
echo '<div class="previous_month"><input name="button" type="submit" value="Previous Month" onClick="javascript:last_month();"></div>';
echo '<div class="show_month">' . date('F', mktime(0, 0, 0, $showmonth)) . ' ' . $showyear . '</div>';
echo '<div class="next_month"><input name="button" type="submit" value="Next Month" onClick="javascript:next_month();"></div>';
echo '</div>';
echo '<div class="week_days">';
echo '<div class="days_of_the_week">Sun</div>';
echo '<div class="days_of_the_week">Mon</div>';
echo '<div class="days_of_the_week">Tues</div>';
echo '<div class="days_of_the_week">Wed</div>';
echo '<div class="days_of_the_week">Thur</div>';
echo '<div class="days_of_the_week">Fri</div>';
echo '<div class="days_of_the_week">Sat</div>';
echo '<div class="clear"></div>';
echo '</div>';
if ($pre_days != 0) {
for($i=1; $i<=$pre_days; $i++) {
echo '<div class="non_cal_day"></div>';
}
}
include ("connect.php");
for ($i=1; $i<= $day_count; $i++) {
$date = $i.'/'.$showmonth.'/'.$showyear;
$query = "Select id FROM events WHERE evDate = '$date'";
$num_rows = 0;
if($result = mysql_query($query)) {
$num_rows = mysql_num_rows($result);
}
if($num_rows > 0) {
$event = "<input name='$date' type='submit' value='Details' id='$date'
onClick='javascript:show_details(this);'>";
}
echo '<div class="cal_day">';
echo '<div class="day_heading">' . $i . '</div>';
if($num_rows != 0) { echo "<div class='openings'><br/>" . $event . "</div>";}
echo '</div>';
}
if ($post_days !=0) {
for($i=1; $i<=$post_days; $i++) {
echo '<div class="non_cal_day"></div>';
}
}
echo '</div>';
?>
工作PHP文件
<html>
<body>
<style>
body
{
background-color:#CD0074;
}
</style>
<form action="http://hr-computing/public/Brodie Evans/project/login.php" method="post">
FirstName: <input type="text" name="firstname" /><br />
Surname: <input type="text" name="surname" /><br />
Email: <input type="text" name="email" /><br />
Password: <input type="password" name="p" id="password"/><br />
<input type="submit" value="Submit"/>
</form>
<?php
$con=mysqli_connect("*****","*******","****","*******");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO Details (FirstName, surname, email)
VALUES('$_POST[firstname]','$_POST[surname]','$_POST[email]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
</body>
</html>
您正在使用哪種環境和編輯器? –
erm ..記事本++和本地主機? – user3181157
是在您的機器上運行加載和配置的PHP的網絡服務器嗎? –