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 } ?>
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 want to use selected option with condition. if $type is room then bed will be selected and if it is bathroom then toilet will be selected. what is wrong with this code. how to correct it????
<html>
<body>
<?php
$type="bathroom";
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<select name="bedtype">
<% if($type=="bathroom"){ %>
<option value="room">BED</option>
<option value="bathroom" selected>TOILET</option>
<% } else { %>
<option value="room" selected>BED</option>
<option value="bathroom" >TOILET</option>
<% } %>
</select>
</form>
</body>
</html>
You are mixing ASP and PHP tags.
While ASP tags were allowed in PHP 5, as of PHP 7, they have been deprecated and removed. You should switch to strictly <?php ?> and <?= ?>.
http://php.net/manual/en/language.basic-syntax.phptags.php
You also have $_SERVER['PHP_SELF'] wrong.
Ternary conditionals would simplify the code greatly. They are in the form if true statement ? do truth : do falsehood. Providing an echo statement before the ternary conditional would echo out the true or false result.
<html>
<body>
<?php $type = "bathroom"; ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="bedtype">
<option value="room" <?php echo $type == "room" ? 'selected' : ''; ?>>BED</option>
<option value="bathroom" <?php echo $type == "bathroom" ? 'selected' : '' ?>>TOILET</option>
</select>
</form>
</body>
</html>
Your code is correct in PHP < 7.0.
You use optional ASP tags ( <% (...) %> ) to embed PHP code.
To activate it, you have to modify your php.ini file turning this line:
asp_tags = Off
in:
asp_tags = On
Please note that ASP tags are rarely used and completely removed on PHP 7.0.
To avoid future incompatibility issue, use standard php tags <?php (...) ?>
As alternative, to echo something, you can use short tags <?= (...) ?>.
So, this:
<?php echo 'Hello World'; ?>
is the same as:
<?= 'Hello World'; ?>
or (you can omit closing semicolon):
<?= 'Hello World' ?>
For the records, there is another short-tag style ( <? (...) ?> ) that must be enabled in php.ini. However, the use of this short-tag is discouraged and substantially abandoned (this style is primary used to identify XML).
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 have an HTML table populated from a mysql database table via PHP with 8 different values.
I need to open a second page and pass to it any one from the values I click on in order to query another from the database.
So far I can open the second page via href but I could solve the parameter issue.
Can anyone help me on this?
The code:
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include "ligabd.php";//connects to the server
if(!$l)
{
die("Ligação sem sucesso: ".mysql_error());
}
else
{
$query="SELECT escalao FROM escaloes ORDER BY idescaloes ASC";
$result= mysqli_query($l, $query);
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<table id="t01" align="center">
<br>
<br>
<br>
<br>
<tr>
<td align="center">Escalões</td>
</tr>
<?php
while ($record= mysqli_fetch_array($result))
{
$r=$record['escalao'];
?>
<tr>
<td>
<a href="pag_escalao_mensalidade.php?escalao=">
<?php
echo $record['escalao'];
?>
</a>
</td>
</tr>
<?php
}
}
?>
</table>
</body>
You should use id in your table and use this:
$query="SELECT id, escalao FROM escaloes ORDER BY idescaloes ASC";
...
while ($record=mysqli_fetch_assoc($result)) // Fetch assoc!
...
<?= $record['escalao'] ?>
....
On the second page, you fetch the record again
$query='SELECT * FROM escaloes WHERE id=' . intval( $_GET['id'] );
This is wrong:
<a href="pag_escalao_mensalidade.php?escalao=">
<?php
echo $record['escalao'];
?>
It should be
<a href="pag_escalao_mensalidade.php?escalao=<?php
^^---
echo $record['escalao'];
?>"><?php echo $record['escalao'] ?>
^^^^^^^---
Note the indicated changes
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...
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>
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
{
}
?>