Multiple conditional Statment error, What's the problem
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 开发者_如何学JAVAOUT! 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.
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.
You are missing condition in elseif.
elseif
should contain a condition. Example:
if (condition1) {
//
} elseif(condition2) {
//
}
精彩评论