skizzy Posted October 11, 2011 Share Posted October 11, 2011 (edited) what im trying to do is set different headers for different classes that i got setup on the register page and have class in the users table but i get [11-Oct-2011 05:20:31] PHP Parse error: syntax error, unexpected $end in C:\xampp\htdocs\header.php on line 45 here is my code <?php $class=$ir['class']; class headers { function startheaders() { global $ir, $set; echo <<<EOF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>{$set['game_name']}</title>} function userdata($ir,$lv,$fm,$cm,$dosessh=1) { global $db,$c,$userid, $set; } if '.$class.'="pirates" { include "header2.php"; } if '.$class.'="nobles" { include "header7.php"; } } } } ?> Edited October 11, 2011 by skizzy Quote Link to comment Share on other sites More sharing options...
newttster Posted October 11, 2011 Share Posted October 11, 2011 Check your curly brackets ... I think you have to many of them. Quote Link to comment Share on other sites More sharing options...
skizzy Posted October 11, 2011 Author Share Posted October 11, 2011 <?php $class=$ir['class']; class headers { function startheaders() { global $ir, $set; echo <<<EOF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>{$set['game_name']}</title>} function userdata($ir,$lv,$fm,$cm,$dosessh=1) { global $db,$c,$userid, $set; } if '.$class.'="pirates" { include "header2.php"; } if '.$class.'="nobles" { include "header7.php"; } } } } ?> Quote Link to comment Share on other sites More sharing options...
skizzy Posted October 11, 2011 Author Share Posted October 11, 2011 i add them after i got the error to fix it as that is one way to fix that error Quote Link to comment Share on other sites More sharing options...
mixmaster Posted October 11, 2011 Share Posted October 11, 2011 get rid of two of the } at the bottom Quote Link to comment Share on other sites More sharing options...
skizzy Posted October 11, 2011 Author Share Posted October 11, 2011 same error [11-Oct-2011 05:38:04] PHP Parse error: syntax error, unexpected $end in C:\xampp\htdocs\header.php on line 43 Quote Link to comment Share on other sites More sharing options...
newttster Posted October 11, 2011 Share Posted October 11, 2011 Yes but if you do a count ... you have 6 opening brackets and 8 closing brackets. Quote Link to comment Share on other sites More sharing options...
Djkanna Posted October 11, 2011 Share Posted October 11, 2011 Try this: <?php class headers { function startheaders() { global $set; echo ' <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>'.htmlentities($set['game_name'], ENT_QUOTES, 'UTF-8').'</title> '; } function userdata ($ir, $lv, $fm, $cm, $dosessh = 1) { if ($ir['class'] == 'pirates') { include 'header2.php'; } else if ($ir['class'] == 'nobles') { include 'header7.php'; } else { //Include a default one perhaps? } } } Quote Link to comment Share on other sites More sharing options...
skizzy Posted October 11, 2011 Author Share Posted October 11, 2011 (edited) ok that script works but had to take out class headers { function startheaders() { global $set; echo ' <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>'.htmlentities($set['game_name'], ENT_QUOTES, 'UTF-8').'</title> '; } now i get [11-Oct-2011 06:19:43] PHP Fatal error: Class 'headers' not found in C:\xampp\htdocs\globals.php on line 74 fixed above error now i get [11-Oct-2011 06:27:34] PHP Fatal error: Call to undefined method headers::menuarea() in C:\xampp\htdocs\globals.php on line 91 and also Djkanna a default isnt necessary because u have to be one or the other as it is set via register Edited October 11, 2011 by skizzy Quote Link to comment Share on other sites More sharing options...
Nickson Posted October 11, 2011 Share Posted October 11, 2011 That's because you took out that part of the code ... the first line is "class headers" which tells php to create that class. Why have you removed that part of the code? you need it.. The function menuarea() should be a part of the headers.php file, if you don't have it, add it. and also Djkanna a default isn't necessary because you have to be one or the other as it is set via register then use the following and leave the else if out if ( $value ="thing") { // action1 } else { // action 2 } Quote Link to comment Share on other sites More sharing options...
mixmaster Posted October 11, 2011 Share Posted October 11, 2011 That's because you took out that part of the code ... the first line is "class headers" which tells php to create that class. Why have you removed that part of the code? you need it.. The function menuarea() should be a part of the headers.php file, if you don't have it, add it. then use the following and leave the else if out if ( $value ="thing") { // action1 } else { // action 2 } Actually he needs to keep the else if Quote Link to comment Share on other sites More sharing options...
Nickson Posted October 11, 2011 Share Posted October 11, 2011 Okay then you tell me what the point is of the following if ($ir['class'] == 'pirates') { include 'header2.php'; } else if ($ir['class'] == 'nobles') { include 'header7.php'; } else { //when you are doing nothing at all } When the script comes to a point where you are not a pirate nor a noble, it won't include any header, and probably breaking everything as I can imagine that the headers have some basic, yet very needed functionality to the page. If the script sets one of the two by default, he can just use an if else and be done with it. You'll also be sure that, no matter what, you'll always include one header. If he uses the current setup, the script will check if the userclass is a pirate, and if not move on to the next check where it will check whether the userclass is a noble. But if it isn't a noble, it will fall back to the else block, which does not exist here. Since these things are set on register, I doubt there will be an issue with the correct working of the code. However, you've added an unneeded check. Also, by not using an else, you don't have any fallback in case something goes wrong. If you only have two options, use an if else, and leave out the else if. If you do use else if's, fine, but at least use an else as well and don't leave it empty... Quote Link to comment Share on other sites More sharing options...
mixmaster Posted October 11, 2011 Share Posted October 11, 2011 DjKanna gave him that part of the script without knowing what else would be added to it, ofcoure there is going to be an header for people that haven't chosen to be a noble or a pirate therefor he needs the elseif in the script before he adds the next part to it Quote Link to comment Share on other sites More sharing options...
Djkanna Posted October 11, 2011 Share Posted October 11, 2011 DjKanna gave him that part of the script without knowing what else would be added to it, ofcoure there is going to be an header for people that haven't chosen to be a noble or a pirate therefor he needs the elseif in the script before he adds the next part to it I did that part, like the way I did as I did not know how you came about becoming a noble or a pirate. It was either a choice of picking which, or being promoted therefore I picked the latter and did it the way I did. Now I know that you have to pick on register, either noble or pirate, a simple if/else will do fine, in that sense Nickson is right. Quote Link to comment Share on other sites More sharing options...
Nickson Posted October 11, 2011 Share Posted October 11, 2011 DjKanna gave him that part of the script without knowing what else would be added to it, ofcoure there is going to be an header for people that haven't chosen to be a noble or a pirate therefor he needs the elseif in the script before he adds the next part to it Check what he originally posted, there are only 2 classes, if a 3rd one would appear, I would find it strange. Otherwise, what DjKanna said :) Quote Link to comment Share on other sites More sharing options...
skizzy Posted October 11, 2011 Author Share Posted October 11, 2011 i got it fixed i went about it a different way i did with the header images and it works fine now thanx for you help mixmaster and djkanna i have also expanded it further so you can only access certain shops as well with your help djkanna Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.