Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have this PHP code:
<?php
session_start();
if (!empty($_SESSION['username'])) {
?>
Welcome, <?= $_SESSION['username'] ?>
<br>
<a href='mcLogout.php'>Logout</a>
<?php
} else {
?>
<p class="da">Don't have an account?</p>
<p><a class="lr" href='registrationpage.php'>Register Here</a></p>
<?php
}
?>
The code is display the username of the user who is in the session (logged) and a link to log out. I wish to know how can I give a style to the username using CSS i.e:
"Welcome, <?=$_SESSION['username']?>"
This part of the code.
you could just wrap it in <span> and do some CSS, like:
...
Welcome, <span class="username"><?=$_SESSION['username']?></span>
...
then css:
.username {
color: #D2D8D9;
font-weight: bold;
....
}
what ever comes between wihle echoing are just like any other HTML element.
<h1>" Welcome, " <?= $_SESSION['username'] ?></h1>
or
Welcome, <h1 class="username"><?= $_SESSION['username'] ?></h1>
Just wrap your "Welcome part in a div"
<?php
session_start();
if (!empty($_SESSION['username'])) {
?>
<div class="welcome-user">Welcome, <?= $_SESSION['username'] ?></div>
<br>
<a href='mcLogout.php'>Logout</a>
<?php
} else {
?>
<p class="da">Don't have an account?</p>
<p><a class="lr" href='registrationpage.php'>Register Here</a></p>
<?php
}
?>
You haven't have short tags <? ... ?> Turned on... I think...
Try <?php ... ?> this will do... and instead of <?=$_SESSION['username']; ?> write <?php echo $_SESSION['username']; ?>
This will work...
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
my php code works fine on local server but does not execute on web server
some of the codes are working.
the code is given down and please tell me problem with the code.
<?php
include("/connect.php");
session_start();
$_SESSION['title']="Portfolio | Mactros Inc.";
include("header.php");
?>
<div>
<center>
<font size=7 class="top">
Portfolio<br />
</font>
<font style="color: #aeafb1;">Home -> Portfolio</font>
</center>
</div>
<div style="height: 650px; margin-top: 10px;">
<?php
$sql = "select * from project";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
?>
<div class="portfolio">
<center>
<img src="<?php echo $row["pic"]; ?>" class="port">
<font size=5><?php echo $row["name"];?></font><br>
<font><?php echo $row["type"];?></font>
</center>
</div>
<?php }?>
</div><?php include("footer.php");?>
in this code gets executed other gets ignored
<?php
include("/connect.php");
session_start();
$_SESSION['title']="Portfolio | Mactros Inc.";
include("header.php");
?> <div>
<center>
<font size=7 class="top">
Portfolio<br />
</font>
<font style="color: #aeafb1;">Home -> Portfolio</font>
include("/connect.php");
This is an absolute path, I don't think your script is at the root of your filesystem, use a relative path instead, and don't disable errors.
Write this line of code at top of you script file to show errors which are occurring into script.
ini_set('display_errors', 1);
error_reporting(E_ALL);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am having multiple images, for that individual image i am having download button
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<button id='dwn_<? echo $a;?>'>Download</button>
<br>
<? } ?>
</div>
If i click that download button i need to save that corresponding image to my local system.
Kindly give some solution for this.
the easiest way without javascript i think it would ( I edited your code, but i cant try it now)
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<form method="get" action='image_<? echo $a;?>.jpg'>
<button id='dwn_<? echo $a;?>' type="submit">Download</button>
</form>
<br>
<? } ?>
</div>
You can delete the id in button if you only use for download
download.php
.........
<?php
if(isset($_REQUEST) && ($_REQUEST['image_name'])){
$filename = $_REQUEST['image_name'].'.jpg';
// Write download code here
}
display_page.php
............
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<a href="download.php?image_name=<?php echo $a; ?>" >Download</a>
<br>
<? } ?>
</div>
Most easiest way by using html 5
<div>
<?php
for($a=0;$a<5;$a++) { ?>
<img src='image_<? echo $a;?>.jpg'/>
<a href='image_<? echo $a;?>.jpg' download>
<span id='dwn_<? echo $a;?>'>Download</span >
</a>
<br>
<? } ?>
</div>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
my php script is givimg me this error, don't know what what's happening :
Parse error: syntax error, unexpected '<' in /home/u381071273/public_html/upload/myfiles.php on line 8 , the follwoing is code that im using to view loggedin user's contents
php code
<?php
include('models/db-settings.php');
include('models/config.php');
include('models/header.php');
$uplfolder = $_REQUEST['folder']; //The folder required by the user.
?>
<?php if(isUserLoggedIn()) {
<div id='main' role='main'>
<div id='blocks'>
<ul class='grid'>
<?php
include 'models/viewdir.php'; //This script opens the user's folders.
?>
</ul></div>
</div>
</body>
}
else
{
}
?>
change line 8 to
<?php if(isUserLoggedIn()) { ?>
You were not closing PHP before starting HTML output
And for line 21:
</body>
<?php }
<?php
include('models/db-settings.php');
include('models/config.php');
include('models/header.php');
$uplfolder = $_REQUEST['folder']; //The folder required by the user.
?>
<?php if(isUserLoggedIn()) { ?>
<div id='main' role='main'>
<div id='blocks'>
<ul class='grid'>
<?php
include 'models/viewdir.php'; //This script opens the user's folders.
?>
</ul></div>
</div>
</body>
//next error will be here
<?php
}
else
{
}
?>
The Problem with the code is that you haven't properly escaped the html part from php
Your Code:
<?php
include('models/db-settings.php');
include('models/config.php');
include('models/header.php');
$uplfolder = $_REQUEST['folder']; //The folder required by the user.
?>
<?php if(isUserLoggedIn()) {
<div id='main' role='main'>
<div id='blocks'>
<ul class='grid'>
<?php
include 'models/viewdir.php'; //This script opens the user's folders.
?>
</ul></div>
</div>
</body>
}
else
{
}
?>
Change it to this :
<?php
include('models/db-settings.php');
include('models/config.php');
include('models/header.php');
$uplfolder = $_REQUEST['folder']; //The folder required by the user.
?>
<?php if(isUserLoggedIn()) { ?>
<div id='main' role='main'>
<div id='blocks'>
<ul class='grid'>
<?php
include 'models/viewdir.php'; //This script opens the user's folders.
?>
</ul></div>
</div>
</body>
<?php
}
else
{
}
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to hide element in my website. I have 2 level access (ad,op). If I logged as sp I can acces Buy, Try, List Upload, and Upload. If I logged as ad, I can access Buy, Try, and List Upload. and not logged, can access Buy and Try.
My code : http://pastebin.com/SvZmzmxK
<p style="text-align:justify;"> </p>
<strong>Buy </strong> <strong> Try</strong>
<?php if ($level=='super_admin') {?>
<strong> List Upload</strong></br></p>
<strong> Upload</strong></br></p>
<?php } elseif($level=='admin') {?>
<strong> List Upload</strong></br></p>
<strong> Upload</strong></br></p>
<?php } ?>
Looking at your code, this is probably just what you are looking for:
<?php
if ($level=='super_admin')
echo "<strong> List Upload</strong>";
else if elseif($level=='admin')
echo "<strong> List Upload</strong></br></p>
<strong> Upload</strong></br></p>";
?>
I would recommend putting your php in a format like this (using echo) since it keeps your code easier to read and maintain.
I also advice you to look at your html knowledge: </br> and </p> can't just be used liked that.
You can try like this:
<p style="text-align:justify;"> </p>
<strong>Buy </strong> <?php //Buy for all; ?>
<strong> Try</strong> <?php //Try for all; ?>
<?php if( in_array($level,array('super_admin','admin')) ){ ?>
<strong> List Upload</strong> <?php //Buy|Try|List Upload for ad+sp; ?>
<?php if($level=='admin'): ?>
<strong> Upload</strong> <?php //Upload is only for admin(ad); ?>
<?php endif; ?>
<?php } ?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am creating a cms and have set up all the pages perfectly but the delete page.
I have this code for my delete.php:
<?php
session_start();
include_once('../include/connection.php');
include_once('../include/article.php');
$article = new Article;
if (isset($_SESSION['logged_in'])) {
$articles = $article->fetch_all();
?>
<html>
<head>
<title>testing</title>
<link rel="stylesheet" href="../style.css" />
</head>
<body>
<div class="container">
CMS
<br /><br />
<form action="delete.php" method="get">
<select onchange="this.form.submit();">
<?php foreach ($articles as $article){ ?>
<option value="<?php echo $article['article_id']; ?>"><?php echo $article['article_title']; ?></option>
<php } ?>
</select>
</form>
</div>
</body>
</html>
<?php
} else {
header('Location: index.php');
}
?>
But in my error log It is telling me this:
PHP Parse error: syntax error, unexpected T_ELSE in /delete.php on line 37
Line 37 is "} else {" please can someone advise me as to where I am going wrong?
thank you.
Your php opening tag is invalid. Change
< php } ?>
to
<?php } ?>