Jump to content

Something wrong with my code.


Glenskie

Recommended Posts

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

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.

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

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.