多个条件语句错误,请问是什么问题
我收到这个错误...
解析错误:语法错误,意外 '{',期待 '(' /home/content/s/k/y/skyview09/html/clients/Cheryl/admin/admin.php 第 122 行
当尝试运行具有多个条件语句(if、elseif、else)的页面时,
。我要运行的 php 是:
<?php
if(isset($_GET['message'])){
echo "<p><font color='#fff'>Your update was successful!</font></p>";
}
require("includes/connection.php");
$article = (isset($_GET['article'])) ? $_GET['article'] : "1";
$page = (isset($_GET['page'])) ? $_GET['page'] : "1";
$nav = (isset($_GET['nav'])) ? $_GET['nav'] : "none";
if($nav != "none"){
$sql = "SELECT id, name, url, title content FROM nav WHERE id='$nav'";
$result = $conn->query($sql) or die('Something is wrong on the test.php...Check it OUT! admin page, navigation');
if($result){
$row = $result->fetch_object();
echo '<form method="post" action="update.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '" />';
echo 'Name: <input type="text" name="name" value="' . $row->name . '" /><br>';
echo 'Url: <input type="text" name="url" value="' . $row->url . '" /><br>';
echo 'Title: <input type="text" name="title" value="' . $row->title . '" /><br>';
echo '<input type="submit" name="editLinks" value="Update Content" />';
echo '</form>';
}
} elseif {
$sql = "SELECT id, content FROM articles WHERE id='$article'";
$result = $conn->query($sql) or die('Something is wrong on the test.php...Check it OUT! admin page, articles');
if($result){
$row = $result->fetch_object();
echo '<form method="post" action="update.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '"';
echo '<textarea name="content" cols="50" rows="15">';
echo $row->content;
echo '</textarea>';
echo '<input type="submit" name="editContent" value="Update Content" />';
echo '</form>';
}
}
else {
$sql = "SELECT id, content FROM pages WHERE id='$page'";
$result = $conn->query($sql) or die('Something is wrong on the test.php...Check it OUT! admin page, pages');
if($result){
$row = $result->fetch_object();
echo '<form method="post" action="update.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '"';
echo '<textarea name="content" cols="50" rows="15">';
echo $row->content;
echo '</textarea>';
echo '<input type="submit" name="editContent" value="Update Content" />';
echo '</form>';
}
}
?>
我希望最后一个“else”语句位于“elseif”语句的位置。 elseif 是最后一个。我尝试了一些解决方案,但没有任何效果。我不知道问题是什么。
我以为我会在 SO 问题中找到我的问题的解决方案,但它们并不完全适合我的问题。我将不胜感激的帮助。
I get this error...
Parse error: syntax error, unexpected
'{', expecting '(' in
/home/content/s/k/y/skyview09/html/clients/Cheryl/admin/admin.php
on line 122
when trying to run a page with multiple conditional statements (if, elseif, else).
The php that I'm tying to run is:
<?php
if(isset($_GET['message'])){
echo "<p><font color='#fff'>Your update was successful!</font></p>";
}
require("includes/connection.php");
$article = (isset($_GET['article'])) ? $_GET['article'] : "1";
$page = (isset($_GET['page'])) ? $_GET['page'] : "1";
$nav = (isset($_GET['nav'])) ? $_GET['nav'] : "none";
if($nav != "none"){
$sql = "SELECT id, name, url, title content FROM nav WHERE id='$nav'";
$result = $conn->query($sql) or die('Something is wrong on the test.php...Check it OUT! admin page, navigation');
if($result){
$row = $result->fetch_object();
echo '<form method="post" action="update.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '" />';
echo 'Name: <input type="text" name="name" value="' . $row->name . '" /><br>';
echo 'Url: <input type="text" name="url" value="' . $row->url . '" /><br>';
echo 'Title: <input type="text" name="title" value="' . $row->title . '" /><br>';
echo '<input type="submit" name="editLinks" value="Update Content" />';
echo '</form>';
}
} elseif {
$sql = "SELECT id, content FROM articles WHERE id='$article'";
$result = $conn->query($sql) or die('Something is wrong on the test.php...Check it OUT! admin page, articles');
if($result){
$row = $result->fetch_object();
echo '<form method="post" action="update.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '"';
echo '<textarea name="content" cols="50" rows="15">';
echo $row->content;
echo '</textarea>';
echo '<input type="submit" name="editContent" value="Update Content" />';
echo '</form>';
}
}
else {
$sql = "SELECT id, content FROM pages WHERE id='$page'";
$result = $conn->query($sql) or die('Something is wrong on the test.php...Check it OUT! admin page, pages');
if($result){
$row = $result->fetch_object();
echo '<form method="post" action="update.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '"';
echo '<textarea name="content" cols="50" rows="15">';
echo $row->content;
echo '</textarea>';
echo '<input type="submit" name="editContent" value="Update Content" />';
echo '</form>';
}
}
?>
I would like the last "else" statement to be in the place of the "elseif" statement. And the elseif to be the last one. I tried some solutions, but nothing really worked. I don't know what the problem is.
I thought I would find the solution already to my problem in the SO questions, but not they're not exactly for my problem. I would appreciate the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题出在您的
elseif
语句中,您需要为elseif
提供一个条件。应该是
我所做的只是阅读了错误。
The problem lies in your
elseif
statement, you need to provide a condition to theelseif
.Should be
All I did was read the error.
您缺少 elseif 中的条件。
You are missing condition in elseif.
elseif
应包含一个条件。示例:elseif
should contain a condition. Example: