Why am I getting an unexpected eof? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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.
Improve this question
I am working on coding this up with a mixture of PHP and HTML but I can't seem to understand why I am getting an eof yet when I exclude the middle php part, it works just fine. i can't seem to understand why it is giving me an error. I compared it to another part of my program and when I looked at a similar page, it works but this one is simply giving me an unexpected eof
Here is the code. Any suggestions?
<!DOCTYPE html>
<?php
require_once( "data.php" );
error_reporting(0);
?>
<html>
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Course Listings</h1>
</div>
<table class="table">
<?php
foreach( $data as $value )
{
?>
<tr>
<td> <? $value[number] ?> </td>
<td> <? $value[name] ?> </td>
<td> <? $value[instructor] ?> </td>
</tr>
<?
};
?>
</table>
</div>
<script src="http://code.jquery.com/jquery.min.js"></script>
</body>
</html>

The closing bracket of your foreach is not being processed because short tags are disabled. This causes the unexpected eof because php still expects a closing bracket.
Use the standard tag <?php everywhere.

Fred-ii most likely had it right in his comment. if that doesn't completely solve it, replace your <table> contents with this and see if it works. As the other guys mentioned, you may have an issue with <?=
<table class="table">
<?php foreach($data as $value ): ?>
<tr>
<td> <?php echo $value['number']; ?> </td>
<td> <?php echo $value['name']; ?> </td>
<td> <?php echo $value['instructor']; ?></td>
</tr>
<?php endforeach; ?>
</table>

Related

php code skipping some html content [closed]

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);

Can someone explain this PHP code? [closed]

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 7 years ago.
Improve this question
<h1 class="site-title">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
rel="home"><?php bloginfo( 'name' ); ?>
</a>
</h1>
if (is_category('Ponies')) { ?>
// overlay a pretty rainbow on the logo for the ponies category
<img id="rainbow"
src='<?php bloiginfo('template_directory');?>/img/rainbow.png"
alt="OMG! Ponies! " />
<?php } ?>
I'm having trouble matching the PHP tags. The comment for the code says "Now any time the category of the content is Ponies, your header also includes the rainbow.png." But it's clear how that is happening. The actual code is on p245 of WordPress Design and Developement by Williams. Thanks for putting another pair of eyes on it.
"If" is not inside <?php ... ?>. Must be:
<?php if (is_category('Ponies')) { ?>
I prefer to use <?php if (condition): ?> when there's HTML in-between.
But anyhow...
1) The if() statement needs to be inside php tags.
2) You don't need echo to retrieve the bloginfo.
bloginfo() documentation
3) You've misspelled bloginfo at the bottom...
My code:
<h1 class="site-title">
<a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
<?php $bloginfo('name'); ?>
</a>
</h1>
<?php if (is_category('Ponies')) : ?>
<img id="rainbow"
src="<?php get_bloginfo('template_directory') . '/img/rainbow.png'; ?>"
alt="OMG! Ponies!" />
<?php endif; ?>

Hide and show element in php [closed]

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 } ?>

delete page is not working [closed]

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 } ?>

How to properly indent PHP/HTML mixed code? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
When mixing PHP and HTML, what is the proper indentation style to use? Do I indent so that the outputted HTML has correct indentation, or so that the PHP/HTML mix looks properly formatted (and is thus easier to read)?
For example, say I have a foreach loop outputting table rows. Which one below is correct?
PHP/HTML mix looks correct:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
Outputted HTML looks correct:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
I've found that when I run into this situation (quite frequently), I don't have a standard style to use. I know that there may not be a "correct" answer, but I'd love to hear thoughts from other developers.
The PHP and the HTML should each be indented so that they are correct with respect to themselves in source form, irrespective of each other and of outputted form:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
I often pondered this question too, but then I realized, who cares what the HTML output looks like? Your users shouldn't be looking at your HTML anyway. It's for YOU to read, and maybe a couple other developers. Keep the source code as clean as possible and forget about what the output looks like.
If you need to debug the output, use Chrome Developer Tools, Firebug, or even F12 Tools.
I generally put opening php tags at the beginning of the line, but indent whatever is inside the tags to match the html formatting. I don't do this, however, for simple echo statements since I use short-open tags. I think it makes simpler it when browsing through the file to find all the declarations.
<table>
<? foreach ($foo as $bar): ?>
<tr>
<? foreach ($bar as $baz): ?>
<td><?=$baz?></td>
<? endforeach ?>
</tr>
<? endforeach ?>
</table>
Direct answer to your question: If you need to read the HTML output often, it might be a good thing to output well indented HTML. But the more common case will be that you need to read your php source code, so it is more important that the source is easily readable.
Alternative to the two options you mentioned: See chaos' or tj111's answer.
Better still in my opinion: Don't mix HTML and php, use a template engine instead.
You can always use a bit of whitespace too to help readability. Building on chaos' indentation:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table
The only downside with this is if you have a lot of mixed code it can make your document twice as long, which makes for more scrolling. Although if you have this much mixed code you may want to consider a templating engine.
You should not be bothered about markup indentation in the production environment. Neither should you use Tidy or other HTML purifiers. There are valid use cases, e.g. when you allow HTML input (but consider using Markdown instead), though these are rare.
Most often HTML beautifiers-filters are abused to hide the underlying issues with the code. Don't. Correct your markup manually.
If you need to indent your code only in the development environment, you can use either of the above. However, beware that these libraries will attempt to fix your markup (that's their primary purpose; indentation is a by-product). I've written Regular Expression based indentation tool Dindent.
Dindent will convert markup like this:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
console.log('te> <st');
function () {
test; <!-- <a> -->
}
</script>
<div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div><table border="1" style="background-color: red;"><tr><td>A cell test!</td>
<td colspan="2" rowspan="2"><table border="1" style="background-color: green;"><tr> <td>Cell</td><td colspan="2" rowspan="2"></td></tr><tr>
<td><input><input><input></td></tr><tr><td>Cell</td><td>Cell</td><td>Ce
ll</td></tr></table></td></tr><tr><td>Test <span>Ce ll</span></td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td></tr></table></div></div>
</body>
</html>
To this:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
console.log('te> <st');
function () {
test; <!-- <a> -->
}
</script>
<div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div>
<table border="1" style="background-color: red;">
<tr>
<td>A cell test!</td>
<td colspan="2" rowspan="2">
<table border="1" style="background-color: green;">
<tr>
<td>Cell</td>
<td colspan="2" rowspan="2"></td>
</tr>
<tr>
<td>
<input>
<input>
<input>
</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Ce ll</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Test <span>Ce ll</span></td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Dindent will not attempt to sanitise or otherwise interfere with your code beyond adding indentation. This is to make your development/debugging easier. Not for production.

Categories