Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\PhpDatabase\index.php on line 68 [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 1 year ago.
I have no idea what's going on, I have looked over the code and it just wont pull up the webpage. I need help figuring out what is going on with this code.
<?php
include ('config.php');
require('db.php');
$query = "SELECT * FROM salerecords";
$result = mysqli_query($conn, $query);
echo $result;
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
mysqli_close($conn);
?>
<html>
<?php include('header.php'); ?>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" type="text/css"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<title>PHP Stores</title>
</head>
<main>
<div id="user_select">
<div id="options">
<div id="view">
<a href="displayRecs.php"><input type="submit" value="View" class="menu-
chosen">
</a>
</div>
</div>
</div>
</main>
<body>
<header>Manage Sales Records</header>
<h1>salesrecords</h1>
<?php foreach($posts as $vaule) : ?>
<div class="well">
<h3><?php echo $vaule['size']; ?>
</h3>
<small>Created on <?php echo $vaule['color'];?> by <?php echo $vaule['price']; ?>
</small>
<p><?php echo $vaule['Description']; ?>
</p>
</div>
</body>
</html>

The error "unexpected end of file" means that when PHP was reading through your code, it was expecting to get to something, but never did. Often, it means you have mismatched brackets, quote marks, etc - you've indicated the start of something, and PHP is waiting for you to indicate the end.
In this case, you have a foreach(): which needs to be paired with an endforeach;

Related

Trouble with pulling data from a dropdown list and checkboxes to be displayed on a table in another page [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
When I remove the name="prod_info" from the option tag in the first document, I this error: Warning: Undefined array key "prod_info" in C:\xampp\htdocs\ordersummary.php on line 51, which I know is because there is not anything that is defined as prod_info. However, when I add the name="prod_info" line back in to the option tag in the first document, I get this error: Parse error: syntax error, unexpected identifier "prod_info", expecting "," or ";" in C:\xampp\htdocs\products.php on line 64. I've tried using separate echo statements to solve the problem of expecting the , or ; symbols, but I get the same error. I've also tried placing the name="prod_info line in the option tag outside of the php section, but I still just get the Warning: Undefined array key "prod_info" in C:\xampp\htdocs\ordersummary.php on line 51 error. I'm confused as to how to get the second page to recognize where to pull the data from without using the POST technique. Thank you in advance for any help you are able to provide! The code for the two pages mentioned is listed below:
//The page the info is to be pulled from:
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link href="novusreset.css" rel="stylesheet" />
<link href="novusstyles1.css" rel="stylesheet" />
<link href="novusstyles2.css" rel="stylesheet" />
<link href="novusflex.css" rel="stylesheet" />
<link href="novusnavicon.css" rel="stylesheet" />
<link href="novustables.css" rel="stylesheet" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<header>
<img src="novuslogo.png" alt="Novus LLC." />
<nav class="horizontal">
<a id="navicon" href="#"><img src="novusnavicon.png" alt="" /></a>
<ul id="navigation">
<li>Home</li>
<li>Products
<ul id="productlist">
<li>PC Parts</li>
<li>Peripherals</li>
<li>Networking</li>
<li>Drinks</li>
<li>Apparel</li>
</ul>
<li>About</li>
<li>Support</li>
<li>Account</li>
<li>Cart</li>
</ul>
</nav>
</header>
<section id="main">
<article id="overview">
<form action="ordersummary.php" method="post">
<label for="products"><h1>Choose a product</h1></label>
<select name="products" id="products">
<option name="orderinfo">
<?php
include('connection.php');
$query = "SELECT * FROM products";
$result = mysqli_query( $conn, $query );
if(mysqli_num_rows($result) > 0) {
while( $row = mysqli_fetch_assoc($result) ){
echo "<option name="prod_info">" . $row["prod_name"] . " $" . $row["prod_price"] . "</option>";
}
} else{
echo "Ahhh yes, the big empty.";
}
mysqli_close( $conn );
?>
</br>
</br>
</option>
</select>
<label class="container">Gift Wrapping
<input type="checkbox">
<span class="checkmark"></span>
</label>
</br>
<label class="container">Gift Tagging
<input type="checkbox">
<span class="checkmark"></span>
</label>
</br>
</br>
<input type="submit" value="Place Order">
</form>
</article>
</section>
<footer>
©2021-Novus LLC. • 201 Main St. • Galena Il
</footer>
</body>
</html>
//The page that displays the info pulled from the above page in table form for the customer.
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link href="novusreset.css" rel="stylesheet" />
<link href="novusstyles1.css" rel="stylesheet" />
<link href="novusstyles2.css" rel="stylesheet" />
<link href="novusflex.css" rel="stylesheet" />
<link href="novusnavicon.css" rel="stylesheet" />
<link href="novustables.css" rel="stylesheet" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<header>
<img src="novuslogo.png" alt="Novus LLC." />
<nav class="horizontal">
<a id="navicon" href="#"><img src="novusnavicon.png" alt="" /></a>
<ul id="navigation">
<li>Home</li>
<li>Products
<ul id="productlist">
<li>PC Parts</li>
<li>Peripherals</li>
<li>Networking</li>
<li>Drinks</li>
<li>Apparel</li>
</ul>
<li>About</li>
<li>Support</li>
<li>Account</li>
<li>Cart</li>
</ul>
</nav>
</header>
<section id="main">
<article id="overview">
<h1>Order Summary</h1></br>
<table id="customers">
<?php
$prod_info = $_POST['prod_info'];
?>
<tr>
<th>Order Details:</th>
</tr>
<tr>
<td><?php echo prod_info;?></br></td>
</tr>
</table>
</article>
</section>
<footer>
©2021-Novus LLC. • 201 Main St. • Galena Il
</footer>
</body>
</html>
Let's take a look at this error: "Parse error: syntax error, unexpected identifier "prod_info", expecting "," or ";" in". The offending line is:
echo "<option name="prod_info">" . $row["prod_name"] . " $" . $row["prod_price"] . "</option>";
The issue here is that you are using double quotes nested inside another set of double quotes. Let's just look at the part before the first period [.].
The first thing happening here is that a string is defined and there is no syntax error:
"<option>"
Next, an attribute is added to the html <option> tag:
"<option name="prod_info">"
There is a set of double quotes inside another set of double quotes which introduces a syntax error. I would suggest using single quotes for the outside and double quotes for the inside. The following code should fix your error:
echo '<option name="prod_info">' . $row["prod_name"] . " $" . $row["prod_price"] . "</option>";
Fixing this issue should also fix your undefined index issue however, I should add that it is always best to check if an array key exists before calling it. Instead of:
$prod_info = $_POST['prod_info'];
You might want to do something like:
$prod_info = isset($_POST['prod_info']) ? $_POST['prod_info'] : '';
or, if you are using php 7.4+:
$prod_info = $_POST['prod_info'] ?? '';

Parse error: syntax error, unexpected end of file in php on line 48 [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
afternoon\am having difficulties in determining the error of the code and i would need assistance. each time i execute the code am given an error in which i am unable to determine the error itself
<?php
include('functions.php');
if (!isLoggedIn()) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Home Page</h2>
</div>
<div class="content">
<!-- notification message -->
<?php if (isset($_SESSION['success'])) : ?>
<div class="error success" >
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>
<!-- logged in user information -->
<div class="profile_info">
<img src="images/user_profile.png" >
<div>
<?php if (isset($_SESSION['user'])) : ?>
<strong><?php echo $_SESSION['user']['username']; ?></strong>
<small>
<i style="color: #888;">(<?php echo ucfirst($_SESSION['user']['user_type']); ?>)</i>
<br>
logout
</small>
<?php endif ?>
</div>
</div>
</div>
</body>
</html>
You are missing a closing bracket in the first lines of your code :
<?php
include('functions.php');
if (!isLoggedIn()) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
} // <- Here is the mistake
?>

php syntax error, closed function incorrectly? [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I get the following error:
unexpected end of file.
I can't figure out why. I think I closed off everything correctly, but there must be something wrong. Please help me!
<?php
function get_header() {
?>
<!DOCTYPE html>
<html>
<head>
<title><? functions\_Title(); ?></title>
<meta name="viewport" content="width=device-width, user-scalable=yes">
<? functions\_IncludeDependances(); ?>
</head>
<body>
<div class="header">
<div class="logo">My e-post</div>
<div class="menu">
<ul>
<li>Index</li>
<li>Blog</li>
<li>About</li>
<li>Contact</li>
</ul>
<div class="membersMenu">
<p><img src="img/user.png" width="20px" height="20px" title="Users area"> Members</p>
</div>
</div>
<div class="spacer"></div>
</div>
<div class="wrapper">
<div class="container">
<? } ?>
Maybe your server is not configured to accept short tags :
try replace
<?
by
<?php
in your file

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>

Notice: Trying to get property of non-object in C:\xampp\htdocs\php\search.php on line 39 [duplicate]

This question already has answers here:
Call to a member function on a non-object [duplicate]
(8 answers)
Closed 7 years ago.
I am trying to create search menu in my website, i am using php and mysqli ,i have created all the credential stuffs which are all required to it but still it showing me some errors,can anyone help me from this.
analyze.php
<!DOCTYPE html>
<html>
<head>
<title>Gtec NetWork</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="asset/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">GTEC Network</a>
<ul class="nav">
<li>Home</li>
<li>Boys</li>
<li>Girls</li>
</ul>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="span12">
<form method="POST" action="search.php">
<label>Search
<input type="text" name="keywords" >
<input type="submit" class="btn btn-primary lg" value="Search">
</label>
</form>
</div>
</div>
</div>
</body>
</html>
search.php
<?php
require_once 'lib/db.php';
?><?php
if (isset($_GET['keywords'])) {
$keywords = $db->escape_string($_GET['keywords']);
$query = $db->query("
SELECT *
FROM user
WHERE registernumber LIKE '%{$keywords}%'
OR username LIKE '%{$keywords}%'
"
);
$run = mysqli_query($query);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Gtec NetWork</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="asset/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">GTEC Network</a>
<ul class="nav">
<li>Home</li>
<li>Boys</li>
<li>Girls</li>
</ul>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-4">
Found<?php echo $query->num_rows;?> results.
<?php
if ($query->num_rows) {
while($r = $query->mysqli_fetch_array())
{
?>
<div class="gylphicon glyphicon-heart">
<?php echo $r->username;?>
</div>
<?php }
}?>
</div>
</div>
</div>
</body>
</html>
The problem is
Found
Notice: Undefined variable: query in C:\xampp\htdocs\php\search.php on line 39
Notice: Trying to get property of non-object in C:\xampp\htdocs\php\search.php on line 39
results.
Notice: Undefined variable: query in C:\xampp\htdocs\php\search.php on line 41
Notice: Trying to get property of non-object in C:\xampp\htdocs\php\search.php on line 41
Please help me
$query is declared inside the if-block
if (isset($_GET['keywords'])) { ... }
So, if $_GET['keywords'] isn't set, $query won't be defined later in the script.
Maybe you can do something like this :
if (isset($_POST['keywords'])) {
$keywords = $db->escape_string($_POST['keywords']);
$query = $db->query("
SELECT *
FROM user
WHERE registernumber LIKE '%{$keywords}%'
OR username LIKE '%{$keywords}%'
"
);
} else {
$query = $db->query("
SELECT *
FROM user
"
);
}
As already pointed out by #dlegall, what is immediatlely sure is: the errors you're getting come from the fact that keywords is currently not set.
From there, two points:
Anyway your code must prevent this case, so you cannot simply use any $query->... in the bottom (HTML) part without surveying it.
So you might use something like:
<div class="col-md-4">
<?php if (#$query) { ?>
Found<?php echo $query->num_rows;?> results.
<?php
if ($query->num_rows) {
while($r = $query->mysqli_fetch_array())
{
?>
<div class="gylphicon glyphicon-heart">
<?php echo $r->username;?>
</div>
<?php }
}?>
<?php } else { ?>
No keywords available.
<?php } ?>
</div>
This way your application is now capable to respond to any situation.
Now you may test for what is currently causing keywords to be empty: this may be a totally different issue.

Categories