以下是我在WAMP 2.5上运行的代码。在MAMP上工作正常,但在WAMP上,它一直给出undefined
变量错误。例如,$dbhandle
是未定义的错误,因为我已经在第49行之前明确定义了它。我感觉PHP解释器没有按顺序访问文件。它直接读取html
和/html
之间的内容,而不是从顶部读取。
<?
ini_set('display_errors',0);
ini_set('display_startup_errors',0);
error_reporting(E_ALL);
include_once 'config.php';
$username = "";
$password = "";
$dbhandle = null;
$row = null;
$username = $config['user'];
$password = $config['password'];
$hostname = $config['server'];
$db = $config['db'];
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)or die(mysql_error($dbhandle));
$selected = mysql_select_db($db,$dbhandle)or die(mysql_error($dbhandle));
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
$query = "Delete from posts WHERE sb_id = $id";
$result = mysql_query($query, $dbhandle) or die(mysql_errno($dbhandle));
$query = "Delete from comments WHERE post_id = $id";
$result = mysql_query($query, $dbhandle) or die(mysql_errno($dbhandle));
header("Location: index.php");
}
?>
<html>
<head>
<title>
Latest Fb Posts
</title>
</head>
<body>
<style>
#container{padding-top: 5%;padding-left: 5%;}
.post{background-color: #e7ecfd;width:90%;padding: 1%;margin-bottom: 2%;}
.post a{font-size: 80%;}
.commentbox{font-size: 90%;font-family: Arial;padding:1%;;margin-top: 2%;margin-bottom: 2%;width: 75%;background-color: #dadbe1;-webkit-border-radius: 3px;}
.author{display: block; width: 50%;color: #1e3493;font-weight: bold;font-size: 70%;padding-bottom: 2%;}
.date{color: #d2d4df;display: block;width: 30%;margin-top: 2%;}
</style>
<?php
$query = "SELECT * FROM posts order by sb_id Asc";
$result = mysql_query($query, $dbhandle);
?>
<div id="container">
<?
while ($row = mysql_fetch_object($result))
{
?>
<div class="post">
<?= $row->content ?>
<span class="date">
<?
$newDate = date("d-M-Y", strtotime($row->post_date));
?>
<?= $newDate ?>
</span>
<br />
<?
$queryComment = "SELECT * from comments where post_id = $row->sb_id";
$resultComment = mysql_query($queryComment, $dbhandle);
while ($rowComment = mysql_fetch_object($resultComment))
{
?>
<div class="commentbox">
<span class="author">Adnan Commented:</span>
<?= $rowComment->content ?>
</div>
<?
}
?>
<a href="index.php?id=<?= $row->sb_id ?>">Delete</a>
</div>
<?
}
?>
</div>
</body>
</html>