多个条件语句错误,请问是什么问题

发布于 2024-09-30 18:49:13 字数 3472 浏览 0 评论 0原文

我收到这个错误...

解析错误:语法错误,意外 '{',期待 '(' /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倒数 2024-10-07 18:49:13

问题出在您的 elseif 语句中,您需要为 elseif 提供一个条件。

} elseif {

应该是

} elseif(some-condition) {

我所做的只是阅读了错误。

The problem lies in your elseif statement, you need to provide a condition to the elseif.

} elseif {

Should be

} elseif(some-condition) {

All I did was read the error.

落日海湾 2024-10-07 18:49:13

您缺少 elseif 中的条件。

You are missing condition in elseif.

唱一曲作罢 2024-10-07 18:49:13

elseif 应包含一个条件。示例:

if (condition1) {
   //
} elseif(condition2) {
   //
}

elseif should contain a condition. Example:

if (condition1) {
   //
} elseif(condition2) {
   //
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文