Jump to content

field submission error


colinjw
Go to solution Solved by mac_gyver,

Recommended Posts

Hi all - I'm really stuck and just need a second set of eyes to please take a look. My description field is being submitted into my entry field - I have gone over and over but can't see the error. Please if you have a mo could you take a look. I know it must be simple but I just can't see it.... :confused:

Thank you,
Colin

// Check if the form has been submitted:
if (isset($_POST['submitted'])) {

	$errors = array();
	
	// Check for a first name:
	if (empty($_POST['title'])) {
	$errors[] = 'You forgot to enter the page Title.';
	} else {
	$title = mysqli_real_escape_string($dbc, trim($_POST['title']));
	}
	
	// Check for a last name:
	if (empty($_POST['intro'])) {
	$errors[] = 'You forgot to enter the page intro.';
	} else {
	$intro = mysqli_real_escape_string($dbc, trim($_POST['intro']));
	}
	
	// Check for entry text:
	if (empty($_POST['entry'])) {
	$errors[] = 'You forgot to enter the page Entry text.';
	} else {
	$entry = mysqli_real_escape_string($dbc, ($_POST['entry']));
	}

	// Check for a page description:
	if (empty($_POST['description'])) {
	$errors[] = 'You forgot to enter the page description text.';
	} else {
	$entry = mysqli_real_escape_string($dbc, ($_POST['description']));
	}
	
	if (empty($errors)) { // If everything's ok.
	
		// Make the query
		$q = "UPDATE pages SET title='$title', intro='$intro', entry='$entry', description='$description' WHERE id=$id LIMIT 1";
		$r = mysqli_query ($dbc, $q);
		if (mysqli_affected_rows($dbc) == 1) { // If it ran ok
		
		// Print a message
		echo '<p>The page has been edited.</p>';
		
		} else { // If it did not run ok
		echo '<p class="error">The page could not be edited due to a system error. We appologise for any inconvenience.</p>'; // Public message.
		
		}
	
	} else { // Report the errors.
	
	echo '<p class="error">The following errors occurred:<br />';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br />\n";
		}
		echo '</p><p>Please try again.</p>';
		
		} // End of if (empty($errors)) IF.
		
	} // End of submit conditional.
	
	// Always show the form...
	
	// Retrieve the page's information:
	$q = "SELECT title, intro, entry, description FROM pages WHERE id=$id";
	$r = mysqli_query ($dbc, $q);
	
if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

	// Get the user's information:
	$row = mysqli_fetch_array ($r, MYSQLI_NUM);
	
	// Create the form:
	echo '<form action="edit_page.php" method="post">
<p>Title: <input type="text" name="title" size="20" maxlength="40" value="' . stripslashes($row[0]) . '" /></p>

<p>Intro: <input type="text" name="intro" size="60" rows="10" value="' . stripslashes($row[1]) . '" /></p>

<p>Entry: <textarea name="entry" rows="15" cols="80">' . stripslashes($row[2]) . '</textarea></p>

<p>Meta Tag Description:<br/><input type="text" name="description" size="60" value="' . stripslashes($row[3]) . '" /></p>

<p><input type="submit" name="submit" value="Submit" /></p>

<input type="hidden" name="submitted" value="TRUE"" />

<input type="hidden" name="id" value="' . $id . '" />
</form>';
Link to comment
Share on other sites

Can you be a little more specific? Being submitted ... WHERE? In the $_POST array? In the Database ? on another page that shows the data? Where is it wrong?

 

If you call print_r($_POST); Are the values associated with the correct key?

 

If you call print_r($row); (after the SELECT) are the values associated with the correct key?

 

Have you checked the database directly (phpmyadmin or command line mysql)?

Link to comment
Share on other sites

try this

// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
     
   $errors = array();
    
	// Check for a first name:
   if (empty($_POST['title'])) {
		$errors[] = 'You forgot to enter the page Title.';
   } else {
		$title = mysqli_real_escape_string($dbc, trim($_POST['title']));
   }
    
	// Check for a last name:
   if (empty($_POST['intro'])) {
		$errors[] = 'You forgot to enter the page intro.';
   } else {
		$intro = mysqli_real_escape_string($dbc, trim($_POST['intro']));
   }
    
	// Check for entry text:
   if (empty($_POST['entry'])) {
		$errors[] = 'You forgot to enter the page Entry text.';
   } else {
		$entry = mysqli_real_escape_string($dbc, ($_POST['entry']));
   }
     
   // Check for a page description:
   if (empty($_POST['description'])) {
		$errors[] = 'You forgot to enter the page description text.';
   } else {
		$entry = mysqli_real_escape_string($dbc, ($_POST['description']));
   }
    
	if (empty($errors)) { // If everything's ok.
	
		echo '<pre>', print_r($_POST). '</pre>';

		// Make the query
		$q = "UPDATE pages 
				SET title='$title', intro='$intro', entry='$entry', description='$description' 
				WHERE id=$id 
				LIMIT 1";
		$r = mysqli_query ($dbc, $q);
    
		if (mysqli_affected_rows($dbc) == 1) { // If it ran ok
			// Print a message
			echo '<p>The page has been edited.</p>';
		} else { // If it did not run ok
			echo '<p class="error">The page could not be edited due to a system error. We appologise for any inconvenience.</p>'; // Public message.
		}
   } else { // Report the errors.
		echo '<p class="error">The following errors occurred:<br />';
    
		foreach ($errors as $msg) { // Print each error.
			echo " - $msg<br />\n";
		}
		
		echo '</p><p>Please try again.</p>';
   } // End of if (empty($errors)) IF.
} // End of submit conditional.
    
// Always show the form...
// Retrieve the page's information:
$q = "SELECT title, intro, entry, description 
		FROM pages 
		WHERE id=$id";
$r = mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.
     
   // Get the user's information:
   $row = mysqli_fetch_array ($r, MYSQLI_NUM);
   
	// Create the form:
   echo '<form action="edit_page.php" method="post">
				<p>Title: <input type="text" name="title" size="20" maxlength="40" value="' . stripslashes($row[0]) . '" /></p>   
				<p>Intro: <input type="text" name="intro" size="60" rows="10" value="' . stripslashes($row[1]) . '" /></p>    
				<p>Entry: <textarea name="entry" rows="15" cols="80">' . stripslashes($row[2]) . '</textarea></p>   
				<p>Meta Tag Description:<br/><input type="text" name="description" size="60" value="' . stripslashes($row[3]) . '" /></p>
				<p><input type="submit" name="submit" value="Submit" /></p>
				<input type="hidden" name="submitted" value="TRUE"" />    
				<input type="hidden" name="id" value="' . $id . '" />
			</form>';
}
Link to comment
Share on other sites

@thara,

 

it is usually best to tell the OP what's wrong with his code, rather than to post "fixed" code that doesn't teach what the problem is or how to troubleshoot what the problem is.

 

the code you posted copy/pasted the same error that the OP has and since you didn't state what you "fixed" in the code you posted, the OP would need to scan through or use a tool to compare what you posted to find LEARN what it is you changed that might have fixed the problem or in this case didn't fix the problem.

Link to comment
Share on other sites

Hi, Thank you all especially mac_gyver :happy-04: .

 

you have a copy/paste typo error on line 31.

 

Also David I know what you mean. I was going over and over. I knew it was a simple typo but couldn't see it. I sometimes think whiping my bare back with bamboo sticks would be less painful and more productive.

 

@mac_gyver I think Thara was trying to show me a tidier way of laying out my code rather than fixing it (as the error is still there). I think. It makes it clearer certainly.

 

Thank you again!

 

Cheers,

Colin

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.