Jump to content

Unclear Errors


MzMel2310

Recommended Posts

Hello,

 

Im new here and I am seeking some assistance. What is pasted below is a piece of code from a project I am working on. However, I am getting errors on the 2 lines that are highlighted in yellow. Anyone have any suggestions as to why these lines are showing errors??

 

Thanks

 

<?php // Script 13.9 - edit_quote.php
/* This script edits a quote. */

// Define a page title and include the heaer:
define('TITLE', 'Edit A Quote');
include('templates/header.html');

print '<h2>Edit A Quotation</h2>';

// Restrict access to administrators only:
if (!is_administrator()) {
print '<h2>Access Denied!</h2><p class="error">You do not have permission to access this page.</p>';
include('templates/footer.html');
exit();
}

// Need the database connection:
include('../mysql_connect.php');

if (isset($_GET['id']) && is_numeric($_GET['id']) && ($_GET['id'] > 0) ) { // Display the entry in a form:

//Define the query:
$query = "SELECT quote, source, favorite FROM quotes WHERE quote_id={$_GET['id']}";
[color=yellow]if ($r = mysql_query($query, $dbc))) { // Run the query.[/color]

	$row = mysql_fetch_array($r); // Retrieve the information.

	// Make the form:
	print '<form action="edit_quote.php" method="post">
		<p><label>Quote <textarea name="quote" rows="5" cols="30">' . htmlentities($row['quote']) . '</textarea></label></p>
		<p><label>Source <input type="text" name="source" value="' . htmlentities($row['source']) . '" /></label></p>
		<p><label>Is this a favorite? <input type="checkbox" name="favorite" value="yes"';

	// Check the box if it is a favorite:
	if ($row['favorite'] == 1) {
		print ' checked="checked"';
	}

	// Complete the form:
	print ' /></label></p>
		<input type="hidden" name="id" value="' . $_GET['id'] . '" />
		<p><input type="submit" name="submit" value="Update This Quote!" /></p>
</form>';

[color=yellow]} else { // Couldnt get the information.[/color]
	print '<p class="error">Could not retrieve the quotation because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}

} elseif (isset($_POST['id']) && is_numeric($_POST['id']) && ($_POST['id'] > 0)) { // Handle the form.

// Validate and secure the form data:
$problem = FALSE;
if ( !empty($_POST['quote']) && !empty($_POST['source']) ) {

	// Prepare the values for storing:
	$quote = mysql_real_escape_string(trim(strip_tags($_POST['quote'])), $dbc);
	$source = mysql_real_escape_string(trim(strip_tags($_POST['source'])), $dbc);

	// Create the "favorite" value:
	if (isset($_POST['favorite'])) {
		$favorite = 1;
	} else {
		$favorite = 0;
	}

} else {
	print '<p class="error">Please submit both a quotation and a source.</p>';
	$problem = TRUE;
}

if (!$problem) {

	// Define the query.
	$query = "UPDATE quotes SET quote='$quote', source='$source', favorite=$favorite WHERE quote_id={$_POST['id']}";
	if ($r = mysql_query($query, $dbc)) {
		print '<p>The quotation has been updated.</p>';
	} else {
		print '<p class="error">Could not update the quotation because:<br />' . mysql_error($dbc) . '</p><p>The query being run was: ' . $query . '</p>';
	}

} // No problem!

} else { // No ID set.
print '<p class="error">This page has been accessed in error.</p>';
} // End of main IF.

mysql_close($dbc); // Close the connection.

include('templates/footer.html'); // Include the footer.
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.