Parse error while [closed] - php

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 8 years ago.
Improve this question
Hello im getting an PHP Error "Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE) in C:\wamp\www\index.php on line 32" any ideas on what im doing wrong?
<?php
include ('includes/db_connect.php');
$query = $db->prepare("SELECT post_id, title, body FROM posts");
$query->execute();
$query->bind_result($post_id, $title, $body);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></head>script>
<![endif]-->
<script scr="http://code.jquery.com/jquery-1.5.min.js"></script>
</head>
<style>
#container{
margin:auto;
width:800px;
}
</style>
<body>
<div id="container">
<?php
while($query->fetch());
?>
<article>
<h2><?php echo $title ?></h2>
<p><?php echo $body?></p>
</article>
<?php endwhile?>
</div>
</body>
</html>

change: while($query->fetch());
to: while($query->fetch()):
(semi-colon to colon)

Related

How do I fetch an image from my DB using ID (PDO)? [closed]

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 yesterday.
Improve this question
I am trying to fetch a product from my products table using PDO concept. I don't know how to fetch the image based on the ID?
Below is what I have included in my script.
require 'includes/db.con.php';
$id= $_GET['id'];
$query = $conn-> prepare("SELECT * FROM PRODUCTS WHERE id ?");
$query ->execute(array($id));
$data= $query->fetchAll(PDO::FETCH_ASSOC);
?>
<html>
<head lang="en-GB" dir="ltr">
<meta charset="utf-8">
<title>Men's Shoes</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="products.css">
</head>
<body>
<!---section content-->
<section>
<h2>men's shoes</h2>
</section>
<!--- Shoes -->
<main id="maincontent">
<figure>
<img src="img/men_shoes/brown_suede_shoes.jpg" alt="brown suede shoes">
<blockquote><b>£40.00</b></blockquote>
<figcaption>Brown Suede Shoes</figcaption>
</figure>

Getting $_GET value within loop [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 6 years ago.
Improve this question
I can't see the problem with this bit of code it seems simple enough, i have a basic webpage:
<?php
include('includes/db_connection.php');
include('includes/functions.php');
include('includes/arrays.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Payday Dreams</title>
<link href='http://fonts.googleapis.com/css?family=Nunito:400,300,700' rel='stylesheet' type='text/css'>
<link href="templates/css/main.css" rel="stylesheet" type="text/css" />
<link href="templates/css/bootstrap_v3.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body{background:url(templates/images/bg_sub.png) repeat-x;}
</style>
<script type="text/javascript" src="templates/js/jquery.js"></script>
<script type="text/javascript" src="templates/js/bootstrap.js"></script>
<script type="text/javascript" src="templates/js/json2.js"></script>
<script type="text/javascript" src="templates/js/common.js"></script>
<script type="text/javascript" src="templates/js/ajax.js"></script>
</head>
<body style="background:#cfe4ee;">
<div style="height:100px; background:#000;">
<div style="width:971px; margin:0 auto; color:#ffffff; font-size:13px;">
<div style="text-align:center; padding-top:10px; font-size:16px; font-weight:bold; font-family:Arial"> <img src="templates/images/small_lock.png" alt="" style="vertical-align:middle" /> Unlock this page to continue!
<br />
<p class="link_ins">TEST</p>
<div id="_ostatus" style="color:#ffffff; font-size:14px; font-weight:normal"> </div>
</div>
</div>
</div>
<div id="linklocker_wrapper">
<div id="contents" style="margin-top:100px;">
<div class="jumbotron">
<div id="offersSection2" style="height:250px; width:570px; margin:25px auto" >
<!-- offer box -->
<div class="offerp_box3" >
<div class="mid" style="height:220px">
<div id="_offers">
<table class="table table-hover table-bordered table-condensed" style="width:530px; background:#ffffff; border:1px solid #cccccc;">
<?php
// get offers from the database
$rows = DB::getInstance()->select('SELECT * FROM `offers` ORDER BY RAND() LIMIT 5');
?>
<?php foreach ($rows as $row) { ?>
<?php
print_r($_GET);
$p = $_GET['p'];
echo $p;
?>
<tr >
<td class="offerDiv" title="<?php echo $row['offer_title']; ?>" style="height:30px; vertical-align:middle">
<div><img src="templates/images/chk.png" alt="" /> <?php echo $row['offer_title']; ?></div>
</td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
<div id="dform" style="display:none; width:90%; text-align:center">
</form>
</div>
</div>
</div>
The URL is like this: http://www.site.co.uk/page.php?l=1p=7 what i'm trying to do is get the value of $_GET['p'] and use it within the foreach loop, when i try to print the value out within the loop it's blank but shows fine before it enters the loop, i have racked the brains i can't think of an alternate way of getting that value, any help would be appreciated.
Is your URL correct at your guess? Believably, what you are trying to do is: http://www.site.co.uk/page.php?l=1&p=7 Notice the & in the URL. You had: http://www.site.co.uk/page.php?l=1p=7. Was that intentional?
In your URL, the two query string parameters need to be separated by &. It's unable to recognize what p is.
http://www.site.co.uk/page.php?l=1&p=7

PHP For Loop in code [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
I am having trouble getting my for loop to work in php. I am trying to make my code loop the time ten times with my css formating
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="clockloop.css">
</head>
<body>
<div id="bodycontainer">
<h1> Clock Loop </h1><hr>
<?php for($i=0;$i<=10;$i++){
<div id="border">
<span id = "font">
<?php
echo date("G:i:s")
?>
</span>
</div>
<h3> Today is
<?php
echo date("F,j,Y")
?>
</h3>
}
?>
</div>
</body>
</html>
You messed up your php tags opening and closing in the wrong places
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="clockloop.css">
</head>
<body>
<div id="bodycontainer">
<h1> Clock Loop </h1><hr>
<?php for($i=0;$i<=10;$i++){?>
<div id="border">
<span id = "font">
<?php
echo date("G:i:s")
?>
</span>
</div>
<h3> Today is
<?php
echo date("F,j,Y")
?>
</h3>
<?php
}
?>
</div>
</body>
</html>
CONVERSELY .. You said you wanted 10 times .. This will output 11, as 0 is still a quantifiable number ..
You cannot just output HTML in PHP like that. You can echo or you can jump in and out like this:
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="clockloop.css">
</head>
<body>
<div id="bodycontainer">
<h1> Clock Loop </h1><hr>
<?php for($i=0;$i<=9;$i++){ ?><!-- note the closing PHP tag -->
<div id="border">
<span id = "font">
<?php
echo date("G:i:s")
?>
</span>
</div>
<h3> Today is
<?php
echo date("F,j,Y")
?>
</h3>
<?php } ?><!-- note the opening PHP tag -->
</div>
</body>
</html>
If you want 10 repeats you should end your count at 9 because 0 will be your first record. You could also start with $i = 1; and use 10 as the count to number.
Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1);this will reveal when you have errors in your syntax and alert you on where you should start debugging.
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="clockloop.css">
</head>
<body>
<div id="bodycontainer">
<h1> Clock Loop </h1><hr>
<?php for($i=0;$i<10;$i++){ ?> => look at this line
<div id="border">
<span id = "font">
<?php
echo date("G:i:s")
?>
</span>
</div>
<h3> Today is
<?php
echo date("F,j,Y")
?>
</h3>
<?php => look at this line
}
?>
</div>

Require/Include in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
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.
Improve this question
I need some help, I have 2 php files and when I am calling some functions it tells me that
Fatal error: Call to undefined function get_contents() in /home/f77inq/public_html/php/shares.php on line 13
eventhough in the files from where I call the functions I have typed require("name ofmy file");
shares.php
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Shares</title>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
adad
<?php
$data = get_contents();
print_contents($data);
?>
</body>
</html>
This is the file from where I am calling the functions.
<?php
require("../../php_include/services.php");
require("../../php_include/query.php");
putenv("ORACLE_HOME=/oracle/product/12.1.0/dbhome_1");
function get_contents() {
$conn = db_connect();
$shares = get_share($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
function print_contents($contents) {
?>
<table>
<tr>
<th>Company Name</th>
<th>Rate</th>
</tr>
<?php
foreach ($contents['shares'] as $share) {
print "<tr>";
//****** LINKS TO EVERY
$identifier = urlencode($share['COMPANY']);
print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
print "<td>{$share['RATE']}</td>";
print "</tr>";
}
?>
</table>
<?php
}
require ("shares.php"); //<<<<<<<<<<<<<<<<<<<<<<
?>
As you can see down bellow I require the shares php file.
Both files are located in the same folder
for testing i put this code in a file named like.php-
<?php
function get_contents() {
echo "Got it";
}
require ("shares.php");
?>
and in the shares.php file i used this-
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Shares</title>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
<?php
$data = get_contents();
echo $data;
?>
</body>
</html>
it works perfectly without eny error.
The error you show is from a file shares.php, yet the file you require is share.php. This error is likely happening somewhere else in the process since all of the code you've shown is valid and certainly works.

PHP short tags not working as expected [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 9 years ago.
Improve this question
I'm trying to make my php page working, by having html code combined with it. Here is a source code:
<?
$username="username";
$password="password";
$db_name="db_name";
mysql_connect('localhost',$username,$password) or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$userstable='profile';
$query = "SELECT * FROM $userstable order by id";
$result = mysql_query($query) or die(mysql_error());
?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DayZSC | Showlist</title>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="styles.css" />
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
<div class="container">
<div id="logo">
<img src="img/logo.png" />
</div>
<?
while ($row=mysql_fetch_array($result)) {
?>
<div class='p_content'>
<h3>
<?
echo ".$row['name'].";
?>
</h3>
<p style="text-align: justify;">
<table align="center"><tbody><tr>
<td>Copies Sold (Week)</td>
<td>11152</td>
</tr>
<tr>
<td>Copies pirated (Week)</td>
<td>124214</td>
</tr>
</tbody></table>
</p>
<h2>Comments</h2><br /><br />
</div>
<?
}
?>
<div id="footer">All rights reserved &copy 2014 | Designed by BerdyevCreations</div>
</div>
</body>
</html>
So whenever I try to run this page, it gives me just a blank. Cannot find error log either. Please help?
I think you are using the PHP short tags wring, try and use this:
<?= $row['name'] ?>
Instead of your
<?
echo ".$row['name'].";
?
I think your problems is with php tags, you are curently using short ones while your php is probably not configured to accept them so change short tags
<?
To long tags
<?php
You need to activate the short code directive in PHP.INI if you have php version 5.3 and earlier
since 5.4 This directive is enabled by default
like this
php.ini
short_open_tag=On

Categories