i want to display Usernames after login or signup in the Navbar using the function links () but the variable holding the username wont show, only displays "$acn";
function links()
{
if(!isset($_SESSION['username']))
{
echo ' <div class="collapse navbar-collapse" id="signup">
<!--<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>-->
<ul class="nav navbar-nav navbar-right" id="signup">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>';
}
else
{
$acn= $_SESSION['username'];
echo '<div class="collapse navbar-collapse" id="signup">
<ul class="nav navbar-nav navbar-right" id="signup">
<li> $acn </li>
<li><span class="glyphicon glyphicon-log-out"></span> Log Out</li>
</ul>
</div>';
}
}
and the function appears like this
<nav class="navbar navbar-inverse" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">OOOO</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#signup">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<?php echo links(); ?>
</div>
</nav>
How do i achieve this please, thanks.
In PHP, if you have a string wrapped in single quotes variables will not be parsed.
'$acn' is just a string with the value $acn. "$acn" will be parsed to be the value of the $acn variable.
Please also note that you are echoing the output of the links() function, but that function has no return value.
While your use of $acn would work fine in double quotesit does not behave in the same manor when contained inside single quotes.
If you wish to use single quotes you must concatenate the string:
<li> '.$acn.' </li>
Other things to note with your code, while using single quotes you will not need to escape double quotes and also there is an echo inside the links function so its not required here: <?php echo links(); ?>
Related
When I try to open the menu on mobile, it does not open and instead, you just select the whole menu bar. It looks like this on the actual website:
meanwhile, this is the relevant code for the navbar.php
<link href="assets/css/style.css" rel="stylesheet">
<nav class="navbar navbar-default">
<div class='container'>
<div class="navbar-header">
<button type="button" id='navbar-toggle' class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="brand">
<img src="assets/img/transparentlogo.png" alt="logo">
</div>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Contact Us</li>
</ul>
</div>
</div>
also, not sure if it makes a difference although the PHP file is named navbar.inc.php
Thank you for taking the time to read this post
<div class="brand">
<img src="assets/img/transparentlogo.png" alt="logo">
</div>
Maybe you should carry brand class' properties to anchor tag and remove brand class.
<a class="brand" href="../index"><img src="assets/img/transparentlogo.png" alt="logo"></a>
Or, you should check if your anchor tag () is covering all the space under the div having "brand" class. In my opinion you cannot click it on phone, because a' is not taking all the width and height.
I just started learning PHP. I have this form that I have set the action to "dashboard.php". But, when I click the submit button, it send the user and variables to a file called newaccount.php. I don't know why this is happening and I have looked over my code. Any suggestions on how I can fix this problem?
Note: The HTML file is called newaccount.html, if that has anything to do with the problem.
HTML:
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.html"> Know Music</a>
</div>
<ul class="nav navbar-nav hidden-xs">
<li>Guitar</li>
<li>Bass</li>
<li>Drums</li>
<li>Piano</li>
</ul>
<ul class="nav navbar-nav navbar-right hidden-xs">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span></a>
<ul class="dropdown-menu">
<li>Log In</li>
<li>Create New Account</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger"></span></a>
<ul class="dropdown-menu">
<li>About</li>
<li>Contact</li>
</ul>
</li>
</ul>
</div>
</nav>
<div class="container">
<div id="buffer">
</div>
<div id="text">
<h8>Create A New Account</h8>
</div>
<div class="form">
<form action="php/dashboard.php" method="post">
<input type="text" class="w3-round-large in" name="email" value="E-Mail"><br>
<br>
<input type="password" class="w3-round-large in" name="wsp" value="Password"><br>
<br>
<input type="submit" class="submit w3-round-large" value="Register">
</form>
</div>
<div class="log">
<p>Already have an account? <a class="link" href="#">Log In Here!</a></p>
</div>
</div>
</body>
PHP (dashboard.php):
<html>
<body>
<?php
$user = $_POST["username"];
$pass = $_POST["wsp"];
echo $user;
echo $pass;
?>
</body>
</html>
I have the following bootstrap navbar. I want to include nav.php into all of my php pages. Well I have done simple includes in the past but with div tags something tells me I am doing this wrong.
<nav class="navbar navbar-fixed-top navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img src="assets/img/logo.png" alt=" "></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<?php include 'nav.php';?>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
My nav.php is as following
echo'
<ul class="nav navbar-nav navbar-right">
<li>HOME</li>
<li>TEAM</li>
<li class="dropdown">
SERVICES <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>IT SERVICES</li>
<li>VOICE SERVICES</li>
</li>
</ul>
</li>
<li>CAREERS</li>
<li>INTERESTING INFORMATION</li>
<li>CONTACT</li>
</ul>';
Two possible paths:
Add <?php tag to your nav.php file,
or
remove echo statement and make the file plain HTML.
I've got trouble with this.
I updated database with example data and navbar got broken. I don't know what cause a problem - maybe you will help me.
So, when I want to go to page "News" or "Projects" nothing happend - just like link had "#" value.
<div class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ URL::base() }}">devprj*</a>
</div>
<div class="collapse navbar-collapse" data-toggle="collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>News</li>
<li>Projects</li>
<li>Forums</li>
<li>About</li>
#if ( !Auth::guest() )
<li>Panel</li>
#endif
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
#if ( Auth::guest() )
<a class="btn btn-default navbar-btn" href="{{ URL::to('login')}}"><span class="glyphicon glyphicon-log-in"></span> Login</a>
<a class="btn btn-success navbar-btn" href="{{ URL::to('register')}}"><span class="glyphicon glyphicon-heart"></span> Register</a>
#else
Welcome, <strong>{{ HTML::link('admin', Auth::user()->username) }} </strong> |
{{ HTML::link('logout', 'Logout') }}
#endif
</ul>
</div><!--/.nav-collapse -->
</div>
Everything works fine exept stuff within navbar-collapse . What's wrong?
I can post more stuff, If that can help.
Bootstrap 3 + Laravel 3.
//pmache
It looks like the issue is the data-toggle="collapse" attribute on the...
<div class="collapse navbar-collapse">
Remove it, and everything should work.
data-toggle="collapse" should only be added to the elements that trigger the collapse event (buttons), and not the elements that are the target of the collapse.
Straigth to the point: I got the twentytwelve Theme from WordPress installed and changed its background + removed the default navbar. (commented it out)
Now how can I implement my bootstrap navbar that float on the top of the screen.
This is the navbar code:
<?php
if(!isset($nosession))
session_start();
}
/*if(isset($_COOKIE['username']))
{
$_SESSION['username'] = $_COOKIE['username'];
$_SESSION['loggedin'] = "true";
}*/
?>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">IHES</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li>Home</li>
<li>Adopteren</li>
<li>WebWinkel</li>
<li>Wall of Steen</li>
<li class="dropdown">
<i class="icon-film" style="margin-top:-1px"></i> Videos <b class="caret"></b>
<ul class="dropdown-menu">
<li><i class="icon-film"></i>Nieuws</li>
<li><i class="icon-film"></i>Interviews</li>
<li><i class="icon-film"></i>Overig</li>
</ul>
</li>
<li>Steenoloog Blog</li>
</ul>
<ul class="nav pull-right">
<?php
if(isset($_SESSION['loggedin'])){
if(isset($_COOKIE['cart']))
{
echo '
<li class="pull-right"><i class="icon-shopping-cart icon-white"></i></li>
';
}
echo '<li class="navbar-form pull-right">
'.$_SESSION['username'].'
</li>';
echo '<li class="navbar-form pull-right">
Loguit
</li>';
}else{
echo '<div class="navbar-form pull-right">
<button type="submit" class="btn">Login Pagina</button>
</div>';
}
?>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
That is my navbar code that I include on top of every .php page.
require "navbar.php";
But how can I use this with in the 2012 theme from wordpress?
I tried to just use the require and also link to the .css files from bootstrap.
But this only gives me the content of the navbar. It is missing the navbar itself.
(BTW: I pasted the code in the header.php file from the theme)
can you include css?
Also try include instead of require