首先,很抱歉代码太长,但我认为它很重要。所有这些都是关于编辑和删除我页面上的新闻。但我不知道为什么它说:语法错误,意外的(最后)等等。有人能帮我摆脱困境吗?此外,当我试图删除其他内容以了解会出现什么时,它没有显示任何内容。只有CSS样式的背景,但没有其他类似的形式等。。
<?php
$servername = "localhost";
$username = "u296093122_admin";
$password = "a";
$dbname = "u296093122_datab";
if(isset($a)){
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("->Pripojenie neúspešné: " . $conn->connect_error);
}
$sql = "SELECT id, nadpis, timestamp FROM Akcie ORDER BY timestamp DESC";
$result = $conn->query($sql);
if (mysql_num_rows($result) > 0){
while($row = mysql_fetch_object($result))
{
?>
<font size="-1"><b><?php echo $row->nadpis; ?></b> <i><?php echo $row->timestamp; ?></i></font>
<br>
<font size="-2"><a href="edit.php?a=edit&id=<?php echo $row->id; ?>">upraviť</a> |
<a href="edit.php?a=delete&id=<?php echo $row->id; ?>">vymazať</a></font>
<?php
}
?>
<font size="-2">No news in the database</font>
<?php
}
mysql_close($conn);
}elseif($a == 'edit'){
if(!isset($update)){
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT nadpis, obsah FROM Akcie WHERE id = '$id'";
$result = $conn->query($sql);
mysql_fetch_object($result);
?>
<form name="form2" method="post" action="edit.php?a=edit&id=<?php echo($id) ?>&update=1">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Nadpis</td>
<td><input name="nadpis" type="text" id="nadpis" value="<?php echo($row->nadpis) ?>"></td>
</tr>
<tr>
<td>Obsah</td>
<td><textarea name="obsah" id="obsah" value="<?php echo($row->obsah) ?>"></textarea></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="hiddenField" type="hidden" value="update">
<input name="add" type="submit" id="add" value="Update">
</div></td>
</tr>
</table>
</form>
<?php
}else{
$sql = "UPDATE Akcie SET nadpis = '$nadpis', obsah = '$obsah', timestamp = NOW() WHERE id = '$id'";
$result = $conn->query($sql);
if(!$result){
echo('Error updating news item: ' . $mysql_error());
exit();
}else{
mysql_close($conn);
echo('Update successful!');
}
} }elseif($a == 'delete'){
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "DELETE FROM Akcie WHERE id = '$id'";
$result = $conn->query($sql);
if(!$result){
echo('Error deleteing news item: ' . $mysql_error());
exit();
}
mysql_close($conn);
echo('News item deleted.');
}
?>
大括号的打开/关闭似乎一团糟。花点时间检查订单。通常,尽量避免混合php逻辑和标记。