Forum Moderators: coopster

Message Too Old, No Replies

php error

         

johnd06

7:13 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



Parse error: syntax error, unexpected '<' in /home1/loftnite/public_html/edit.php on line 108

line 108:<form method="post" action="edit.php">

entire code:

<?php
//The following PHP script allows you to edit the
//contents of your MySQL table.
//Connecting to the MySQL database
require('dbconnect.php');

//Should we show a single item or a list?
if($_POST['edit']) {
//Simplifying the variables.

$id = $_POST['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$date = $_POST['date'];
//trim() strips white space from the beginning and end of a line.
$date = trim($date);

$content = $_POST['content'];

//Checks for empty fields or invalid date.
if((empty($title)) OR (empty($author)) OR (empty($date)) OR (empty($content))) {
echo "<center><strong>Please fill in all fields!</strong></center>
";

} else {
//explode() separates the date by the '/' character and outputs it to an array.
$explode_date = explode('/', $date);
//checkdate() returns FALSE if the date is invalid.
$check_date = checkdate($explode_date[0], $explode_date[1], $explode_date[2]);
if($check_date == false) {

echo "<center><strong>Invalid date entered!</strong></center>
";
} else {
//htmlspecialchars() converts special characters into HTML entities.
$title = htmlspecialchars($title);
$author = htmlspecialchars($author);

//The MySQL query which will update the content in the table.
$query = "UPDATE news SET title = '$title', author = '$author', date = '$date', content = '$content' WHERE ID = '$id'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "<center><strong>News item modified!</strong></center>";

}
}
} elseif($_GET['action'] == "edit") {
//Display a single result.
$id = $_GET['id'];
//The MySQL query. Select all from the table news where the ID equals the id sent in URL.

$query = "SELECT * FROM news WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);

<form method="post" action="edit.php"> (line 108)
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" value="echo'$title'; " maxlength="250" /></td></tr>
<tr><td align="right">Author:</td><td><input type="text" name="author" value="echo '$author'; " maxlength="250" /></td></tr>
<tr><td align="right">Date:</td><td><input type="text" name="date" value="echo '$date'; " maxlength="10" /></td></tr>
<tr><td align="right">Content:</td><td><textarea name="content" cols="50" rows="10">echo'$content'; </textarea></td></tr>

<tr><td> </td><td><input type="hidden" name="id" value=" echo '$ID'; " /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>

}
} else {
//Since we're not displaying a single result,
//we're going to display a list of results.

//The MySQl query. Selects all from the table news.
$query = "SELECT * FROM news ORDER BY ID DESC";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
echo '<table><tr><td><strong><a href="edit.php?action=edit&id=$ID">$title</a></strong></td></tr>
<tr><td><small>Written by $author on $date</small></td></tr>';

<tr><td><strong><a href="delete.php?id=$ID">DELETE</a></strong></td></tr>?>

penders

7:29 pm on Jul 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The problem is that you have raw HTML in the middle of your PHP source. It looks like you need to
echo
this HTML block (as you have done in other parts of your code) - but you also need to tidy up the echo statements within the value attributes of this HTML.

The very last line of your code appears to have the same problem.

johnd06

2:22 am on Jul 24, 2008 (gmt 0)

10+ Year Member



could you be more specific?

eelixduppy

5:23 am on Jul 24, 2008 (gmt 0)



The following section of code:

<form method="post" action="edit.php">
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" value="echo'$title'; " maxlength="250" /></td></tr>
<tr><td align="right">Author:</td><td><input type="text" name="author" value="echo '$author'; " maxlength="250" /></td></tr>
<tr><td align="right">Date:</td><td><input type="text" name="date" value="echo '$date'; " maxlength="10" /></td></tr>
<tr><td align="right">Content:</td><td><textarea name="content" cols="50" rows="10">echo'$content'; </textarea></td></tr>
<tr><td> </td><td><input type="hidden" name="id" value=" echo '$ID'; " /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>

is not properly written. Let's use heredoc syntax [us3.php.net] to correct it now:


echo <<<HTML
<form method="post" action="edit.php">
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" value="$title" maxlength="250" /></td></tr>
<tr><td align="right">Author:</td><td><input type="text" name="author" value="$author" maxlength="250" /></td></tr>
<tr><td align="right">Date:</td><td><input type="text" name="date" value="$date" maxlength="10" /></td></tr>
<tr><td align="right">Content:</td><td><textarea name="content" cols="50" rows="10">$content</textarea></td></tr>
<tr><td> </td><td><input type="hidden" name="id" value="$ID" /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>
HTML;

Take careful note of the changes that I made between the two pieces of code. Also, as was already said, the last line has a similar issue as it's not being echoed to the screen properly and the PHP interpreter thinks it's PHP code.

So this line here:


<tr><td><strong><a href="delete.php?id=$ID">DELETE</a></strong></td></tr>?>

can be made with just a basic echo:


echo '<tr><td><strong><a href="delete.php?id=' . $ID .'">DELETE</a></strong></td></tr>';
?>

eelixduppy

5:24 am on Jul 24, 2008 (gmt 0)



By the way, Welcome to WebmasterWorld! :)

johnd06

12:00 am on Jul 25, 2008 (gmt 0)

10+ Year Member



thanks, sorry if im being a pest but... now im getting "Parse error: syntax error, unexpected $end in /home1/loftnite/public_html/edit.php on line 167"

line 167 is the very last line of code which is </html>

the entire code is :
<!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" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:413px;
top:63px;
width:200px;
height:212px;
z-index:1;
}
.style1 {color: #FFFFFF}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body id="page1">

<table class="table">
<tr>
<td class="site_center">
<table class="site_center1">
<tr>
<td id="header">
<div class="indent">
<a href="#"><img alt="" src="images/text_banner.jpg" class="txt_banner" width="93" height="39" /></a><br />
<a href="index.html"><img alt="" src="images/logo.jpg" width="334" height="75" /></a> </div></td>
</tr>
<tr>
<td id="content">
<div class="block">
<div class="top">
<div class="bottom">
<div class="inside">
<p align="center">Wl<span class="style1">Welcome to Loft Night Club.</span></p>
<table width="100%" height="207" border="0">

<tr>
<td width="100%">
<?php
//The following PHP script allows you to edit the
//contents of your MySQL table.
//Connecting to the MySQL database
require('dbconnect.php');

//Should we show a single item or a list?
if($_POST['edit']) {
//Simplifying the variables.

$id = $_POST['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$date = $_POST['date'];
//trim() strips white space from the beginning and end of a line.
$date = trim($date);

$content = $_POST['content'];

//Checks for empty fields or invalid date.
if((empty($title)) OR (empty($author)) OR (empty($date)) OR (empty($content))) {
echo "<center><strong>Please fill in all fields!</strong></center>
";

} else {
//explode() separates the date by the '/' character and outputs it to an array.
$explode_date = explode('/', $date);
//checkdate() returns FALSE if the date is invalid.
$check_date = checkdate($explode_date[0], $explode_date[1], $explode_date[2]);
if($check_date == false) {

echo "<center><strong>Invalid date entered!</strong></center>
";
} else {
//htmlspecialchars() converts special characters into HTML entities.
$title = htmlspecialchars($title);
$author = htmlspecialchars($author);

//The MySQL query which will update the content in the table.
$query = "UPDATE news SET title = '$title', author = '$author', date = '$date', content = '$content' WHERE ID = '$id'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "<center><strong>News item modified!</strong></center>";

}
}
} elseif($_GET['action'] == "edit") {
//Display a single result.
$id = $_GET['id'];
//The MySQL query. Select all from the table news where the ID equals the id sent in URL.

$query = "SELECT * FROM news WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.
echo <<<HTML
<form method="post" action="edit.php">
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" value="$title" maxlength="250" /></td></tr>
<tr><td align="right">Author:</td><td><input type="text" name="author" value="$author" maxlength="250" /></td></tr>
<tr><td align="right">Date:</td><td><input type="text" name="date" value="$date" maxlength="10" /></td></tr>
<tr><td align="right">Content:</td><td><textarea name="content" cols="50" rows="10">$content</textarea></td></tr>
<tr><td> </td><td><input type="hidden" name="id" value="$ID" /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>
HTML;

}
} else {
//Since we're not displaying a single result,
//we're going to display a list of results.

//The MySQl query. Selects all from the table news.
$query = "SELECT * FROM news ORDER BY ID DESC";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
echo '<table><tr><td><strong><a href="edit.php?action=edit&id='.$ID.'">$title</a></strong></td></tr>
<tr><td><small>Written by $author on $date</small></td></tr>';

echo '<tr><td><strong><a href="delete.php?id=' . $ID .'">DELETE</a></strong></td></tr>';
?>

</td>
</tr>
</table>
</div>
</div>
</div>
</div></td>
</tr>
<tr>
<td id="footer">
<div class="indent">
<div class="row_1">
<ul class="footer_menu">
<li><a class="current" href="index-1.html">home page</a></li>
<li><a href="index-2.html">about us</a></li>
<li><a href="index-3.html">our menu</a></li>
<li><a href="index-4.html">concerts</a></li>
<li><a href="index-5.html">our gallery</a></li>
<li><a href="index-6.html">our news</a></li>
<li><a href="index-7.html">download</a></li>
<li><a href="index-8.html">locations</a></li>
</ul>
</div>
Copyright 2007 &copy; Night Club. All rights reserved. <span><a href="index-9.html">Privacy Policy</a></span> ¦ <span><a href="#">Terms Of Use</a></span></div></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

eelixduppy

12:21 am on Jul 25, 2008 (gmt 0)



You are missing a closing parenthesis somewhere. Check the parenthesis in your code.

johnd06

12:58 am on Jul 25, 2008 (gmt 0)

10+ Year Member



I can't seem to find missing parenthesis... anyhow thanks for you help i'll keep looking.

eelixduppy

4:48 am on Jul 25, 2008 (gmt 0)



I'm sorry. I was typing in haste and used to wrong word! I meant "brace" (}) not parenthesis. You are missing a closing brace! From your example above, I can at least see that your while loop isn't closed. There may be others. Sorry about that...

johnd06

6:53 pm on Jul 26, 2008 (gmt 0)

10+ Year Member



hey thank for all your help, i found it and fixed it... but the form isn't loading the data from the database.... maybe i'm doing something wrong?