Glenskie Posted April 9, 2014 Share Posted April 9, 2014 im trying to check if the account is = to c but its erroring out and displays a blank page. $user = '<script type="text/javascript" src="'.$actual_link.'/js/submenu.js"></script><div class="dropdown"> <a class="account" > <span>'.$username.'</span> </a> <div class="submenu" style="display: none; "> <ul class="root"> '. if ($account == "c") { .' <li> <a href="/stats.php">Dashboard</a> </li> '. } .' Link to comment https://forums.phpfreaks.com/topic/287648-something-wrong-with-my-code/ Share on other sites More sharing options...
gizmola Posted April 9, 2014 Share Posted April 9, 2014 You can't concatenate a logical block onto a string. Instead, you should end your string, then evaluate the block and append to the string as needed. $user = '<script type="text/javascript" src="'.$actual_link.'/js/submenu.js"></script><div class="dropdown"> <a class="account" > <span>'.$username.'</span> </a> <div class="submenu" style="display: none; "> <ul class="root">'; if ($account == "c") { $user .= '<li> <a href="/stats.php">Dashboard</a> </li>'; } Please look into templating, even if that is simply via includes, as well as alternative PHP syntax. PHP already allows you to intermingle PHP and HTML, and with heavy HTML like this, the approach you are taking is difficult to read and maintain. Link to comment https://forums.phpfreaks.com/topic/287648-something-wrong-with-my-code/#findComment-1475571 Share on other sites More sharing options...
X5HOST Posted April 9, 2014 Share Posted April 9, 2014 Hi Glenskie, It looks like you're trying to add an 'if' statement whilst declaring a variable, this will return an error (or blank page with errors in the log). I would recommend the following: if ($account == 'c') { $variable = ' <li> <a href="/stats.php">Dashboard</a> </li>'; } else { $variable = ''; } $user = '<script type="text/javascript" src="'.$actual_link.'/js/submenu.js"></script><div class="dropdown"> <a class="account" > <span>'.$username.'</span> </a> <div class="submenu" style="display: none; "> <ul class="root"> '.$variable ; Kind Regards, Jason Moore Link to comment https://forums.phpfreaks.com/topic/287648-something-wrong-with-my-code/#findComment-1475572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.