Schlo_50 Posted June 18, 2008 Share Posted June 18, 2008 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 More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 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"); } ?> Link to comment https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/#findComment-568169 Share on other sites More sharing options...
rarebit Posted June 18, 2008 Share Posted June 18, 2008 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... Link to comment https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/#findComment-568170 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 Check my last edit Link to comment https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/#findComment-568172 Share on other sites More sharing options...
Schlo_50 Posted June 18, 2008 Author Share Posted June 18, 2008 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"); } Link to comment https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/#findComment-568179 Share on other sites More sharing options...
rarebit Posted June 18, 2008 Share Posted June 18, 2008 Block wise that looks ok (I think) Link to comment https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/#findComment-568183 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 <? } else { include("./inc/client_form.htm"); } elseif($_GET['action'] == "Add_Sub") { ?> What is that elseif doing following that else? Link to comment https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/#findComment-568187 Share on other sites More sharing options...
Schlo_50 Posted June 18, 2008 Author Share Posted June 18, 2008 Wicked. Thanks Link to comment https://forums.phpfreaks.com/topic/110755-solved-unexpected-t_else/#findComment-568189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.