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
{
}
?>
Related
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 6 years ago.
Improve this question
I am trying to create an if else statement where if the "if" part is true, a menu icon is displayed that says "Registration" and takes the user to a registration page. If the "else" part is true, the menu will display the user's name that is registered. I have attached basically how I would like it to look, I just do not know how to incorporate my div into a PHP if else statement.
<?PHP
session_start();
if ($_SESSION['email'] == '')
{
"<div id='cssmenu'>
<ul>
<li>
Registration
</li>
</ul>
</div>"
}
else
{
"<div id='cssmenu'>
<ul>
<li>
<a> "Greetings " . $_SESSION['fname'] </a>
</li>
</ul>
</div>"
}
?>
The following should do the trick. As mentioned by #Ghost, you need echo and you needed to change a few quotes to single quotes.
<?PHP
session_start();
if ($_SESSION['email'] == '')
{
echo "<div id='cssmenu'>
<ul>
<li>
<a href='registration.php'> Registration</a>
</li>
</ul>
</div>";
}
else
{
echo "<div id='cssmenu'>
<ul>
<li>
Greetings " . $_SESSION['fname'] . " </a>
</li>
</ul>
</div>";
}
?>
you can use php whitin html
the php code is only considered between php tags so anything else is put directly to browser
as i can see only one part of your html changes so a better design would be
<?php session_start(); ?>
<div id="cssmenu">
<ul>
<li>
<?php if ($_Session['email']=='') {
?>
Registration
<?php }else{ ?>
Greetings -> <?php echo $_SESSION['fname']; ?>
<?php }?>
</li>
</ul>
</div>
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
currently I'm developing a application using Codeigniter framework and PHP. In there I need to include below mentioned PHP code in between HTML tags.
Can anyone provide a solution or an guidance for this?
PHP code :
if(isset($_SESSION['email']))
{
echo '<a href="http://localhost/ci/myads_view">';
echo 'MY ADS' ;
echo '</a>';
}
HTML code:
<nav class="main-navigation dd-menu toggle-menu" role="navigation">
<ul class="sf-menu"/>
</nav>
You can come in and out of PHP at will:
<?php if(isset($_SESSION['email'])) { ?>
MY ADS
<?php } ?>
In the above, if the PHP if statement evaluates to true, the HTML within the conditional will execute, otherwise it will not.
In your particular case, I can only assume this is what you're trying to do:
<nav class="main-navigation dd-menu toggle-menu" role="navigation">
<ul class="sf-menu">
<li>
<?php if(isset($_SESSION['email'])) { ?>
MY ADS
<?php } else { ?>
OTHER LINK
<?php } ?>
</li>
</ul>
</nav>
Or something along the lines of the above?
PHP is pretty cool, you can stop/resume it mid-document.
For example like this, I hope this is the solution to what you were trying to do:
<?php
if(isset($_SESSION['email']))
{ /* this will temporarily "stop" php --> */ ?>
<a href="http://localhost/ci/myads_view">
<nav class="main-navigation dd-menu toggle-menu" role="navigation">
<ul class="sf-menu">
</a>
<?php /* <-- php resumes now */
}
?>
So what's going on?
First, you write your IF statement and the curly brackets, the code inside of which would usually be executed if the IF statement evaluates to TRUE.
<?php
if(something==true)
{
echo "write something to the page";
}
?>
But instead of using PHP commands, you quickly jump out of PHP by closing the PHP tag ?> as you would do at the end of your PHP code anyway.
<?php
if(something==true)
{
?>
Now you can continue in plain HTML without all the usual related issues of PHP commands as escaping characters like ' and " and \ watching your "qoute level" and so on. Instead, you write bog standard HTML.
When you're done entering the HTML that should be output in case the IF statement is true, just open another PHP tag and close the IF statement's curly brackets and, if that's the end of your PHP, close the PHP tag as well.
<?php
}
?>
What you have done is correct, additionally you can write as follows:
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
echo $str;
Reference - http://php.net/manual/en/language.types.string.php
To put the link inside the navigation, you can do it like this, all inside the same PHP file.
<?php
if(isset($_SESSION['email'])) {
$navLink= 'MY ADS';
}
?>
<nav class="main-navigation dd-menu toggle-menu" role="navigation">
<ul class="sf-menu"><?php echo($navLink); ?>
This should work:
<?php if(isset($_SESSION['email'])): ?>
<nav class="main-navigation dd-menu toggle-menu" role="navigation">
<ul class="sf-menu">
<?php endif; ?>
I am making a cms application and it was working fine until i made a new page called "session.php" and added a function into that page I then wrote the require once command into the main page of my application and when I run it says "Webpage is not available"...i remove the require once command and my application works again. Does anyone know how to fix this problem?
This is the code for session.php
<?php session_start(); function message() {
if (isset($_SESSION["message"])) {
$output = "<div class=\"message\">";
$output .= htmlentities($_SESSION["message"]);
$output .= "</div>";
return $output;
}}?>
This is the code for the page im trying to load
<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/db_connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php include("../includes/layouts/header.php"); ?>
<?php find_selected_page(); ?>
<div id="main">
<div id="navigation">
<?php echo navigation($current_subject, $current_page); ?>
<br />
+ Add a subject
</div>
<div id="page">
<?php echo message(); ?>
<?php if ($current_subject) { ?>
<h2>Manage Subject</h2>
Menu name: <?php echo $current_subject["menu_name"]; ?>
<?php } elseif ($current_page) { ?>
<h2>Manage Page</h2>
Menu name:<?php echo $current_page["menu_name"]; ?>
<?php } else { ?>
Please select a subject or a page.
<?php }?>
</div>
</div>
<?php include("../includes/layouts/footer.php"); ?>
The code posted looks oddly-formatted, but I'll venture to say it's not a syntax error.
As others stated, you need to learn the "debugging" process which includes monitoring the error.log file (assuming Apache) and the browser's console (where applicable).
During development, it's a good idea to turn on error reporting to make this a bit easier. Place the following lines at the top of your PHP scripts:
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
That won't display 100% of the issues (99.8% give or take), so read up on how to view your server's error log. The answer to your question is hidden in there, I guarantee it.
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 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...