colinjw Posted June 2, 2013 Share Posted June 2, 2013 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.... 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/ Share on other sites More sharing options...
DavidAM Posted June 2, 2013 Share Posted June 2, 2013 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)? Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/#findComment-1433621 Share on other sites More sharing options...
Solution mac_gyver Posted June 2, 2013 Solution Share Posted June 2, 2013 you have a copy/paste typo error on line 31. Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/#findComment-1433624 Share on other sites More sharing options...
DavidAM Posted June 2, 2013 Share Posted June 2, 2013 Don't know how I missed that. I scanned through the code looking specifically for that and did not see it. I guess its time to get my eyes checked. Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/#findComment-1433629 Share on other sites More sharing options...
thara Posted June 2, 2013 Share Posted June 2, 2013 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/#findComment-1433630 Share on other sites More sharing options...
mac_gyver Posted June 2, 2013 Share Posted June 2, 2013 @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. Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/#findComment-1433647 Share on other sites More sharing options...
colinjw Posted June 2, 2013 Author Share Posted June 2, 2013 Hi, Thank you all especially mac_gyver . 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 Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/#findComment-1433677 Share on other sites More sharing options...
Jessica Posted June 2, 2013 Share Posted June 2, 2013 Get a good IDE - we have a thread in misc about various ones. Quote Link to comment https://forums.phpfreaks.com/topic/278678-field-submission-error/#findComment-1433678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.