Jump to content

[SOLVED] Unexpected T_ELSE


Schlo_50

Recommended Posts

Hi there,

 

I am getting the unexpected T_ELSE error but Im not sure how to get around it. I am trying to find out whether an ID is in use, and if so redirect the user. If the ID is not in use I want to include a file.

 

elseif($_GET['action'] == "New_Client") {
$file = file("data/clients.DAT");
	foreach($file as $key => $val){
		$data[$key] = explode("|", $val);
		$match = trim($data[$key][0]);
if ($_GET['vid'] == $match){
print "<meta http-equiv=\"refresh\" content=\"0;url=?id=main\">";
}
}
else {
include("./inc/client_form.htm");
}
}

 

Thanks in advance guys

Link to comment
https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/
Share on other sites

It helps to properly format your code with tabs. I don't know what you have above this elseif, so there's no telling where your error is. But I formatted it how it should look:

 

EDIT: I think I found it. You were closing the loop and doing else when not closing the if statement.

 

<?php
elseif($_GET['action'] == "New_Client") {
$file = file("data/clients.DAT");
foreach($file as $key => $val){
	$data[$key] = explode("|", $val);
	$match = trim($data[$key][0]);

	if ($_GET['vid'] == $match){
		print "<meta http-equiv=\"refresh\" content=\"0;url=?id=main\">";
	}
} 
} else {
include("./inc/client_form.htm");
}
?>

I agree, good indentation always helps the eyes...

 

But here I have slightly diff...

...
}
elseif($_GET['action'] == "New_Client")
{
$file = file("data/clients.DAT");
foreach($file as $key => $val)
{
	$data[$key] = explode("|", $val);
	$match = trim($data[$key][0]);
	if ($_GET['vid'] == $match)
	{
		print "<meta http-equiv=\"refresh\" content=\"0;url=?id=main\">";
	}
}
}		//	*** here
else
{
include("./inc/client_form.htm");
}
//}	//	*** ??

 

also don't know what lurks above...

The code above is as follows: (Includes indented code.)

 

if($_GET['action'] == "Add_Client") {

$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
$d = $_POST['d'];
$e = $_POST['e'];
$f = $_POST['f'];
$g = $_POST['g'];
$h = $_POST['h'];
$i = $_POST['i'];
$j = $_POST['j'];

		$content = "$a|$b|$c|$d|$e|$f|$g|$h|$i|$j|";
		$content = $content."\n";
		$content = stripslashes($content);

		$fh = fopen("data/clients.DAT", "a+");
		fwrite($fh, $content);
		fclose($fh);

		$title = "Client Added";
		$msg = "A new head office has been added to the contact list.";
		$link = "?id=operate&action=Manage_Clients";
		echo success_msg($title, $msg, $link);
}

elseif($_GET['action'] == "New_Client") {
$file = file("data/clients.DAT");
foreach($file as $key => $val){
	$data[$key] = explode("|", $val);
	$match = trim($data[$key][0]);

	if ($_GET['vid'] == $match){
		print "<meta http-equiv=\"refresh\" content=\"0;url=?id=main\">";
	}
} 
} else {
include("./inc/client_form.htm");
}

elseif($_GET['action'] == "Add_Sub") {

include("./inc/sub_client_form.php");

$file = file("data/clients.DAT");
	foreach($file as $key => $val){
		$data[$key] = explode("|", $val);
		$match = trim($data[$key][0]);

		if ($_GET['vid'] == $match){
		print "<meta http-equiv=\"refresh\" content=\"0;url=?id=main\">";
		}
}
include("./inc/sub_client_form.htm");
}

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.