Jump to content


Edit page HELP


11 replies to this topic

#1 Dat

    Young Padawan

  • Members
  • Pip
  • 55 posts
  • Gender:Male

Posted 11 September 2007 - 05:59 PM

Sorry for making a topic every-time I have an PHP error, but I want to learn, really.

I made this edit page from a tutorial and I got this error:
Parse error: syntax error, unexpected $end in /***/edit.php on line 71

with this code:
Line 71 is the last line in this code, which is ?>
<?php
//Connect to database
****

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

$id = $_POST['id'];
$title = $_POST['title'];
$summary_synopsis = $_POST['summary_synopsis'];
$opening_theme = $_POST['opening_theme'];

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

} else {
//htmlspecialchars() converts special characters into HTML entities.
$title = htmlspecialchars($title);
$summary_synopsis = htmlspecialchars($summary_synopsis);


//The MySQL query which will update the content in the table.
$query = "UPDATE anime_reviews SET title = '$title', summary_synopsis = '$summary_synopsis', opening_theme = '$opening_theme' WHERE ID = '$id'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "<center><strong>Review entry 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 anime_reviews 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">
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" value="<?php echo "$title"; ?>" maxlength="250" /></td></tr>
<tr><td align="right">summary_synopsis:</td><td><input type="text" name="author" value="<?php echo "$summary_synopsis"; ?>" maxlength="250" /></td></tr>
<tr><td align="right">opening_theme:</td><td><input type="text" name="date" value="<?php echo "$opening_theme"; ?>" maxlength="10" /></td></tr>
<tr><td> </td><td><input type="hidden" name="id" value="<?php 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 anime_reivews 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 Arrangements</small></td></tr><tr><td><strong><a href=\"delete.php?id=$ID\">DELETE</a></strong></td></tr>";
?>

Thanks for the help again.

Edited by Dat, 18 September 2007 - 04:45 PM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 11 September 2007 - 06:25 PM

When you get that error, it means the parser unexpectedly reached the end of the page, prematurely; in other words, there is an unclosed bracket set somewhere.


There is a closing bracket missing from the very last else statement.

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 11 September 2007 - 11:10 PM

2 brackets actually. I don't see one for the while loop either.

#4 Killswitch

    Young Padawan

  • Members
  • Pip
  • 20 posts

Posted 11 September 2007 - 11:11 PM

Your last else clause has no closing bracket, and just by quick glance, I think one should be right before the very last line infront of ?>

You should check out ConTEXT editor or any other free editor that can highlight PHP syntax. With Context, you can paste all that, click your brackets and it will show all matching brackets. Helps easily narrow where any are missing.

EDIT - Good catch RC, it is missing one.
EDIT 2 - Looks like all while loops are missing closing brackets.

Edited by Killswitch, 11 September 2007 - 11:13 PM.


#5 Dat

    Young Padawan

  • Members
  • Pip
  • 55 posts
  • Gender:Male

Posted 12 September 2007 - 12:18 AM

Thank you all, I just started using Coda and it's more useful than dreamweaver. I just discovered right now when I added in the two missing brackets that it indicates what it is closing with a blue blink circle. Really handy. Thanks again

Closed Else and the While Loop

#6 Dat

    Young Padawan

  • Members
  • Pip
  • 55 posts
  • Gender:Male

Posted 16 September 2007 - 11:43 AM

Great now...
When I click 'edit' it echo's Please fill in all required fields!

<?php
//connect...
if($_POST['edit']) { 
//Simplifying the variables.

$title = mysql_real_escape_string( $_POST['title'] );
$titlejap = mysql_real_escape_string( $_POST['titlejap'] );
$image= mysql_real_escape_string( $_POST['image'] );
$genres = mysql_real_escape_string( $_POST['genres'] );
$formats = mysql_real_escape_string( $_POST['formats'] );
$episode_number = mysql_real_escape_string( $_POST['episode_number'] );
$length = mysql_real_escape_string( $_POST['length'] );
$year = mysql_real_escape_string( $_POST['year'] );
$opening = mysql_real_escape_string( $_POST['opening'] );
$ending = mysql_real_escape_string( $_POST['ending'] );
$site = mysql_real_escape_string( $_POST['site'] );
$summary = mysql_real_escape_string( $_POST['summary'] );
$episode = mysql_real_escape_string( $_POST['episode'] );
$last_updated = date("Y-m-d");
//Checks for empty fields
if(empty($title) OR (empty($summary)) {
echo "<center><b>Please fill in all required fields!</b></center>
";

} else {
//The MySQL query which will update the content in the table.
$query = "UPDATE `anime_reviews` SET title = `$title`, title_jap = `$titlejap`, image = `$image`, genres = `$genres`, formats = `$format`, episode_number = `$episode_number`, length = `$length`, year_published = `$year`, opening_theme = `$opening`, ending_theme = `$ending`, official_sites = `$sites`, last_updated = `$last_updated`, summary_synopsis = `$summary`, episodes = `$episode`, last_updated = `$last_updated` WHERE ID = `$id`";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "<center><strong>Review entry 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 anime_reviews WHERE ID='$id'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
extract($row);
//Transform them into html special charactors
$title = htmlspecialchars($title);
$titlejap = htmlspecialchars($title_jap);
$summary = htmlspecialchars($summary_synopsis);
$genres = htmlspecialchars($genres);
$formats = htmlspecialchars($formats);
$episode_number = htmlspecialchars($episode_number);
$length = htmlspecialchars($length);
$year = htmlspecialchars($year_published);
$opening = htmlspecialchars($opening_theme);
$ending = htmlspecialchars($ending_theme);
$site = htmlspecialchars($official_sites);
$episode = htmlspecialchars($episodes);
//Now the form!
?>
<form method="post" action="edit.php">
<table border="0" cellspacing="5" cellpadding="0">
  <tr>
	<td>Title:</td>
	<td>
		<input type="text" value="<?php echo "$title"; ?>" />	</td>
  </tr>
  <tr>
	<td>Japanese Title:</td>
	<td><input type="text" value="<?php echo "$titlejap"; ?>" /></td>
  </tr>
  <tr>
	<td>Summary:</td>
	<td>
	  <textarea cols="45" rows="5"><?php echo "$summary"; ?></textarea></td>
  </tr>
  <tr>
	<td>Image name:</td>
	<td><input type="text" value="<?php echo "$image"; ?>"/></td>
  </tr>
  <tr>
	<td>Genres:</td>
	<td><textarea cols="45" rows="5"><?php echo "$genres"; ?></textarea></td>
  </tr>
  <tr>
	<td>Formats:</td>
	<td><textarea cols="45" rows="5"><?php echo "$formats"; ?></textarea></td>
  </tr>
  <tr>
	<td># of episodes:</td>
	<td><input type="text" value="<?php echo "$episode_number"; ?>"/></td>
  </tr>
  <tr>
	<td>Length:</td>
	<td><input type="text" value="<?php echo "$length"; ?>" /></td>
  </tr>
  <tr>
	<td>Date published:</td>
	<td><input type="text" value="<?php echo "$year"; ?>" /></td>
  </tr>
  <tr>
	<td>Opening theme:</td>
	<td><textarea cols="45" rows="5"><?php echo "$opening"; ?></textarea></td>
  </tr>
  <tr>
	<td>Ending theme:</td>
	<td><textarea cols="45" rows="5"><?php echo "$ending"; ?></textarea></td>
  </tr>
  <tr>
	<td>Sites:</td>
	<td><textarea cols="45" rows="5"><?php echo "$site"; ?></textarea></td>
  </tr>
  <tr>
	<td>Episodes:</td>
	<td><textarea cols="45" rows="5"><?php echo "$episode"; ?></textarea></td>
  </tr>
  <tr>
	<td>&nbsp;</td>
	<td><input type="hidden" value="<?php echo "$id"; ?>" /><input type="submit" name="edit" value="edit" />
   </td>
  </tr>
</table>
</form>
<?
}
} else {
$query = "SELECT * FROM anime_reviews ORDER BY ID DESC";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
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 Arrangements</small></td></tr><tr><td><strong><a href=\"delete.php?id=$id\">DELETE</a></strong></td></tr>";
}
}
?>

I even tried limiting it to:
if(empty($title)) {


#7 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 16 September 2007 - 11:47 AM

Look at your form elements. None of them have name properties, which is why they aren't being passed through the form to PHP.

You need them to look like this, for example. Basic HTML.

<input type="text" name="title" value="<?php echo "$title"; ?>" />


#8 Dat

    Young Padawan

  • Members
  • Pip
  • 55 posts
  • Gender:Male

Posted 16 September 2007 - 08:17 PM

Thanks, but now I have an error message: Unknown column '' in 'where clause'

#9 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 16 September 2007 - 09:13 PM

Look at your SQL queries.

For one thing, your UPDATEs aren't structured right. The tick mark (`) is for signifying a column in the database. If you are inserting strings, use single quotes (').
Also, on this remark, use tick marks (`) around column names. In this case, ID might be something of a value to MySQL, so it is replacing it with whatever. Use like `ID`, and so on for all your columns, and you should be fine.

#10 Dat

    Young Padawan

  • Members
  • Pip
  • 55 posts
  • Gender:Male

Posted 19 September 2007 - 05:21 PM

Doesn't work now.. says 'success' but it didn't really edit! I don't get what I'm doing wrong?

<?php
//The following PHP script allows you to edit the
//Connect to database
//Should we show a single item or a list?
if($_POST['edit']) {
//Simplifying the variables.
//mysql_real_escape_string to make it safer...
$id = $_POST['id'];
$title = mysql_real_escape_string( $_POST['title'] );
$titlejap = mysql_real_escape_string( $_POST['japtitle'] );
$image= mysql_real_escape_string( $_POST['image'] );
$genres = mysql_real_escape_string( $_POST['genres'] );
$format = mysql_real_escape_string( $_POST['format'] );
$episode_number = mysql_real_escape_string( $_POST['episode_number'] );
$length = mysql_real_escape_string( $_POST['length'] );
$year = mysql_real_escape_string( $_POST['year'] );
$opening = mysql_real_escape_string( $_POST['opening'] );
$ending = mysql_real_escape_string( $_POST['ending'] );
$site = mysql_real_escape_string( $_POST['site'] );
$summary = mysql_real_escape_string( $_POST['summary'] );
$episode = mysql_real_escape_string( $_POST['episode'] );
$last_updated = date("Y-m-d");
echo $titlejap;
//Check if any fields are empty or not
if((empty($title)) OR (empty($genres)) OR (empty($format)) OR (empty($summary))) {
echo "<center><b>Please fill in all required fields!</b></center>
";

} else {
	//The MySQL query which will update the content in the table.
	$query = "UPDATE anime_reviews SET title = '$title', title_jap = '$titlejap', image = '$image', genres = '$genres', formats = '$format', episode_number = '$episode_number', length = '$length', year_published = '$year', opening_theme = '$opening', ending_theme = '$ending', official_sites = '$site', summary_synopsis = '$summary', episodes = '$episode', last_updated = '$last_updated' WHERE id = '$id'";
	//Execute the query.
	$result = mysql_query($query) or die(mysql_error());
	echo "Review has been added!<br>
	".$title."<br><br>
	(".$titlejap.")<br><br>
	".$summary."";

}
} 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 anime_reviews WHERE ID='$id'";
	$result = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($result)) {
	extract($row);
	//Transform them into html special charactors
	$title = htmlspecialchars($title);
	$japtitle = htmlspecialchars($title_jap);
	$summary = htmlspecialchars($summary_synopsis);
	$genres = htmlspecialchars($genres);
	$format = htmlspecialchars($formats);
	$episode_number = htmlspecialchars($episode_number);
	$length = htmlspecialchars($length);
	$year = htmlspecialchars($year_published);
	$opening = htmlspecialchars($opening_theme);
	$ending = htmlspecialchars($ending_theme);
	$site = htmlspecialchars($official_sites);
	$episode = htmlspecialchars($episodes);
	//Now the form!
?>
<form method="post" action="edit.php">
<table border="0" cellspacing="5" cellpadding="0">
  <tr>
	<td>Title:</td>
	<td>
		<input type="text" name="title" value="<?php echo "$title"; ?>" />	</td>
  </tr>
  <tr>
	<td>Japanese Title:</td>
	<td><input type="text" name="japtitle" value="<?php echo "$japtitle"; ?>" /></td>
  </tr>
  <tr>
	<td>Summary:</td>
	<td>
	  <textarea cols="45" name="summary" rows="5"><?php echo "$summary"; ?></textarea></td>
  </tr>
  <tr>
	<td>Image name:</td>
	<td><input type="text" name="image" value="<?php echo "$image"; ?>"/></td>
  </tr>
  <tr>
	<td>Genres:</td>
	<td><textarea cols="45" rows="5" name="genres"><?php echo "$genres"; ?></textarea></td>
  </tr>
  <tr>
	<td>Formats:</td>
	<td><textarea cols="45" rows="5" name="format"><?php echo "$format"; ?></textarea></td>
  </tr>
  <tr>
	<td># of episodes:</td>
	<td><input type="text" name="episode_number" value="<?php echo "$episode_number"; ?>"/></td>
  </tr>
  <tr>
	<td>Length:</td>
	<td><input type="text" name="length" value="<?php echo "$length"; ?>" /></td>
  </tr>
  <tr>
	<td>Date published:</td>
	<td><input type="text" name="year" value="<?php echo "$year"; ?>" /></td>
  </tr>
  <tr>
	<td>Opening theme:</td>
	<td><textarea cols="45" rows="5" name="opening"><?php echo "$opening"; ?></textarea></td>
  </tr>
  <tr>
	<td>Ending theme:</td>
	<td><textarea cols="45" rows="5" name="ending"><?php echo "$ending"; ?></textarea></td>
  </tr>
  <tr>
	<td>Sites:</td>
	<td><textarea cols="45" rows="5" name="site"><?php echo "$site"; ?></textarea></td>
  </tr>
  <tr>
	<td>Episodes:</td>
	<td><textarea cols="45" rows="5" name="episode"><?php echo "$episode"; ?></textarea></td>
  </tr>
  <tr>
	<td>&nbsp;</td>
	<td><input type="hidden" value="<?php echo "$id"; ?>" /><input type="submit" name="edit" value="Finish Update" />
   </td>
  </tr>
</table>
</form>
<?
	}
} else {
	$query = "SELECT * FROM anime_reviews ORDER BY ID DESC";
	$result = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($result)) {
	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 Arrangements</small></td></tr><tr><td><strong><a href=\"delete.php?id=$id\">DELETE</a></strong></td></tr>";
	}
}
?>


#11 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 19 September 2007 - 06:50 PM

Your hidden field doesn't have a name. As in my comment a few posts up, you need to have a name attribute on any form fields; HTML 101.

[quote]<input type="hidden" name="id" value="<?php echo $id; ?>" />[/quote]

Edited by Demonslay, 19 September 2007 - 06:50 PM.


#12 Dat

    Young Padawan

  • Members
  • Pip
  • 55 posts
  • Gender:Male

Posted 20 September 2007 - 08:02 AM

[quote name='Demonslay' post='236177' date='Sep 19 2007, 04:50 PM']Your hidden field doesn't have a name. As in my comment a few posts up, you need to have a name attribute on any form fields; HTML 101.

[quote]<input type="hidden" name="id" value="<?php echo $id; ?>" />[/quote]
[/quote]

Hey thanks for fixing my stupid mastake

How can I remove the rn

I see them after every





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users