pindi
09-18-2009, 04:53 PM
I hate to post about something as straightforward as a parse error, but I honestly can't puzzle this one out. The error is as follows:
Parse error: parse error in C:\XAMPP\xampp\htdocs\pindi_2009\loggedin.php on line 26
Although the problem isn't on line 26 (that's the line that says $order_by = "PortfolioNumber ASC"; ) because if I comment out that line, the line with the error moves 'up' (e.g. "parse error...on line 24, 21, 8 and so on). So I tried commenting out and moving up and I got to this section on or about here:
<?php #Script 11.9 loggedin.php #2
//The use is redirected here from login.php.
session_start(); //Start the session.
//If no session value is present, redirect the user.
if (!isset($_SESSION['ID_num'])) {
require_once('login_functions.php');
$url=absolute_url();
header("Location: $url");
exit();
}
So basically right at the beginning.
Everything worked fine until I added the 'sort order' code (at about line 17). But I guess I must have deleted or added a space or something that shouldn't be there. I've tried playing around with quotation marks and spacing to no avail. Tried to check the brackets and braces and it seems to jive ok.
I get the sinking feeling I'm missing something obvious, but what? Can it be some kind of error passed along from the 'login_functions.php' page that's causing the parse error?
For reference, here is the entire page of code:
<?php #Script 11.9 loggedin.php #2
//The use is redirected here from login.php.
session_start(); //Start the session.
//If no session value is present, redirect the user.
if (!isset($_SESSION['ID_num'])) {
require_once('login_functions.php');
$url=absolute_url();
header("Location: $url");
exit();
}
$page_title='Logged In!';
//Print a customized message:
echo "<p>You are now logged in, {$_SESSION['First']}!</p>
<a href=\"logout.php\">Logout</a></p>";
require_once('connect.php');
//fixing the sort order
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'id';
switch ($sort){
case 'id':
$order_by = "IDNumber ASC";
break;
case 'ti':
$order_by = "Title ASC";
break;
case 'po':
$order_by = "PortfolioNumber ASC";
break;
case 'me':
$order_by = "Medium ASC";
break;
case 'we'
$order_by = "Web ASC";
break;
}
//Getting the info
$q = "SELECT * FROM art ORDER BY $order_by";
$r = @mysqli_query ($dbc, $q);
?>
<table border="1px"><tr><b><td><a href = "loggedin.php?sort=id">IDNumber</a></td><td><a href = "loggedin.php?sort=ti">Title</a></td>
<td><a href = "loggedin.php?sort=po">Portfolio Number</a></td><td><a href = "loggedin.php?sort=me">Medium</a></td><td><a href = "loggedin.php?sort=we">On web</a></td></b></tr>
<?php
if($r){
while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)){
?>
<tr><td><?=$row['IDNumber']?></td><td><?=$row['Title']?></td><td><?=$row['PortfolioNumber']?></td><td><?=$row['Medium']?></td><td><?=$row['Web']?></td></td>
<?php
}
}
else
{echo mysqli_error($dbc);}
?>
</table>
<?php mysqli_close($dbc); ?>
Parse error: parse error in C:\XAMPP\xampp\htdocs\pindi_2009\loggedin.php on line 26
Although the problem isn't on line 26 (that's the line that says $order_by = "PortfolioNumber ASC"; ) because if I comment out that line, the line with the error moves 'up' (e.g. "parse error...on line 24, 21, 8 and so on). So I tried commenting out and moving up and I got to this section on or about here:
<?php #Script 11.9 loggedin.php #2
//The use is redirected here from login.php.
session_start(); //Start the session.
//If no session value is present, redirect the user.
if (!isset($_SESSION['ID_num'])) {
require_once('login_functions.php');
$url=absolute_url();
header("Location: $url");
exit();
}
So basically right at the beginning.
Everything worked fine until I added the 'sort order' code (at about line 17). But I guess I must have deleted or added a space or something that shouldn't be there. I've tried playing around with quotation marks and spacing to no avail. Tried to check the brackets and braces and it seems to jive ok.
I get the sinking feeling I'm missing something obvious, but what? Can it be some kind of error passed along from the 'login_functions.php' page that's causing the parse error?
For reference, here is the entire page of code:
<?php #Script 11.9 loggedin.php #2
//The use is redirected here from login.php.
session_start(); //Start the session.
//If no session value is present, redirect the user.
if (!isset($_SESSION['ID_num'])) {
require_once('login_functions.php');
$url=absolute_url();
header("Location: $url");
exit();
}
$page_title='Logged In!';
//Print a customized message:
echo "<p>You are now logged in, {$_SESSION['First']}!</p>
<a href=\"logout.php\">Logout</a></p>";
require_once('connect.php');
//fixing the sort order
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'id';
switch ($sort){
case 'id':
$order_by = "IDNumber ASC";
break;
case 'ti':
$order_by = "Title ASC";
break;
case 'po':
$order_by = "PortfolioNumber ASC";
break;
case 'me':
$order_by = "Medium ASC";
break;
case 'we'
$order_by = "Web ASC";
break;
}
//Getting the info
$q = "SELECT * FROM art ORDER BY $order_by";
$r = @mysqli_query ($dbc, $q);
?>
<table border="1px"><tr><b><td><a href = "loggedin.php?sort=id">IDNumber</a></td><td><a href = "loggedin.php?sort=ti">Title</a></td>
<td><a href = "loggedin.php?sort=po">Portfolio Number</a></td><td><a href = "loggedin.php?sort=me">Medium</a></td><td><a href = "loggedin.php?sort=we">On web</a></td></b></tr>
<?php
if($r){
while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)){
?>
<tr><td><?=$row['IDNumber']?></td><td><?=$row['Title']?></td><td><?=$row['PortfolioNumber']?></td><td><?=$row['Medium']?></td><td><?=$row['Web']?></td></td>
<?php
}
}
else
{echo mysqli_error($dbc);}
?>
</table>
<?php mysqli_close($dbc); ?>