Jump to content

Parse Error: Unknow T_ELSE


zearN

Recommended Posts

Im getting the Parse error: parse error, unexpected T_ELSE in D:\Programmer\xampp\htdocs\newssystem\edit.php on line 72 when im trying to run the edit file in my php news system. The lines of code i think it is about is these: } else {
$query = "SELECT * FROM news ORDER BY ID DESC";
$result = mysql_query($query) or die(mysql_error());
}
Link to comment
https://forums.phpfreaks.com/topic/34153-parse-error-unknow-t_else/
Share on other sites

I didnt know what to post exactly so i posted it all. I hope you want to help me anyway. Im a little new to php and im still learning it.
<?php
require('dbconnect.php');

if($_POST['edit']) {

$id = $_POST['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$date = $_POST['date'];
//trim() strips white space from the beginning and end of a line.
$date = trim($date);

$content = $_POST['content'];

//Checks for empty fields or invalid date.
if((empty($title)) OR (empty($author)) OR (empty($date)) OR (empty($content))) {
echo "<center><strong>Please fill in all fields!</strong></center>
";

} else {
//explode() separates the date by the '/' character and outputs it to an array.
$explode_date = explode('/', $date);
//checkdate() returns FALSE if the date is invalid.
$check_date = checkdate($explode_date[0], $explode_date[1], $explode_date[2]);
if($check_date == false) {

echo "<center><strong>Invalid date entered!</strong></center>
";
} else {
//htmlspecialchars() converts special characters into HTML entities.
$title = htmlspecialchars($title);
$author = htmlspecialchars($author);


//The MySQL query which will update the content in the table.
$query = "UPDATE news SET title = '$title', author = '$author', date = '$date', content = '$content' WHERE ID = '$id'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "<center><strong>News item modified!</strong></center>";

}
}
} elseif($_GET['action'] == "edit") {
//Display a single result.
$id = $_GET['id'];
//The MySQL query. Select all from the table news where the ID equals the id sent in URL.

$query = "SELECT * FROM news WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
}
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
}
{
php?>
<form method="post" action="edit.php">
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" value="<?php echo "$title"; ?>" maxlength="250" /></td></tr>
<tr><td align="right">Author:</td><td><input type="text" name="author" value="<?php echo "$author"; ?>" maxlength="250" /></td></tr>
<tr><td align="right">Date:</td><td><input type="text" name="date" value="<?php echo "$date"; ?>" maxlength="10" /></td></tr>
<tr><td align="right">Content:</td><td><textarea name="content" cols="50" rows="10"><?php echo "$content"; ?></textarea></td></tr>

<tr><td> </td><td><input type="hidden" name="id" value="<?php echo "$ID"; ?>" /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>
<?php
} else ($_GET['action']== "edit"){
$title = $_GET[title]
$query = "SELECT * FROM news ORDER BY ID DESC";
$result = mysql_query($query) or die(mysql_error());
}
while ($row = mysql_fetch_array($result)) {

extract($row);
echo "<table><tr><td><strong><a href=\"edit.php?action=edit&id=$ID\">$title</a></strong></td></tr>";
echo "<tr><td><small>Written by $author on $date</small></td></tr>";

echo "<tr><td><strong><a href=\"delete.php?id=$ID\">DELETE</a></strong></td></tr>";
}
php?>

<?php
//The following PHP script deletes entries from your MySQL database..
//Connecting to the MySQL database
require('dbconnect.php');

//Naming some variables here.
$id = $_GET['id'];
$id2 = $_POST['id'];


if($_POST['deny']) {
$path = "http://".$_SERVER['HTTP_HOST']."/edit.php";
header("Location: $path");
exit;
} elseif($_POST['confirm']) {

//The MySQl query. Deletes an entry from the database.
$query = "DELETE FROM news WHERE ID = '$id2'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "The entry has been deleted";
header("Refresh: 2; edit.php");
} else {
php?>
<table align="center">;
<form action="delete.php" method="post">
<tr><td>Do you really want to delete this entry?</td></tr>
<tr><td><input type="hidden" name="id" value="<?php echo "$id"; ?>";/><input type="submit" name="confirm" value="Yes" /><input type="submit" name="deny" value="No" /></td></tr>
<?php
}
php?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.