Merdok Posted January 14, 2009 Share Posted January 14, 2009 Hi guys, It's been a long time but I decided to start playing with PHP again, I've been writing a CMS for a website i'm making and this page is giving me grief, i've used this script in some of my other websites in the past and its been fine so I'm assuming i've made a typo somewhere but I can't for the life of me find it. No matter what I do I get the 'all fields must be filled' message pop up, if I remove the validation then I get the success message but the DB doesnt update! here is the code: if(isset($_GET['ID'])) { // Pulls the data from the database $dblookup = "SELECT pageID, pageName, articleTitle, articleBody, meta_key, meta_desc FROM core_content WHERE pageID=" . $_GET['ID']; $data = mysql_query($dblookup) or die('Failed to return data: ' . mysql_error()); /* sorts the data into variables and puts them in an array ready to be called when needed */ list($pageID, $pageName, $articleTitle, $articleBody, $meta_key, $meta_desc) = mysql_fetch_array($data, MYSQL_NUM); } elseif (!empty($_POST['submit'])) { if (empty($articleTitle) || empty($articleBody) || empty($pageName) || empty($meta_key) || empty($meta_desc)) { $message = '<strong><p class="error">All fields MUST be filled</p></strong>'; $pageID = $_POST['pageID']; $articleTitle = $_POST['articleTitle']; $articleBody = $_POST['articleBody']; $pageName = $_POST['pageName']; $meta_key = $_POST['meta_key']; $meta_desc = $_POST['meta_desc']; } else { $pageID = $_POST['pageID']; $articleTitle = $_POST['articleTitle']; $articleBody = $_POST['articleBody']; $pageName = $_POST['pageName']; $meta_key = $_POST['meta_key']; $meta_desc = $_POST['meta_desc']; // Updates the database $dbupdate = "UPDATE core_content ". "SET articleTitle = '$articleTitle', pageID = '$pageID', articleBody = '$articleBody', pageName = '$pageName', meta_key = '$meta_key', meta_desc = '$meta_desc'". "WHERE pageID = '$pageID'"; mysql_query($dbupdate) or die('<h3 class="error"> Update Failed! </h3>' . mysql_error()); // Return a message if successful. $message = '<strong><p class="success">Page updated</p></strong>'; } } ?> <h3> <?php echo "Curently Editing: " . $pageName ;?></h3> <h3> <?php echo $message; ?> <p class="error"> WARNING: This will modify core pages on the website, please ensure you have the appropriate permissions to perform this task, errors can cause the site to fail.</p> <form enctype="multipart/form-data" action="pages_edit.php" method="post"> <input name="pageID" type="hidden" id="pageID" size="3" value="<?php echo $pageID ?>"> <p> <label>Short Headline<br /> <input name="pageName" type="text" id="pageName" size="50" value="<?php echo $pageName ?>"> </label> </p> <p> <label>Full Headline<br /> <input name="articleTitle" type="text" id="articleTitle" size="50" value="<?php echo $articleTitle ?>"> </label> </p> <p> <label>Body Text<br /> <textarea name="articleBody" id="articleBody" cols="50" rows="15"><?php echo $articleBody ?></textarea> </label> </p> <p> <label>Keywords (At least 5 - separeted by commas) <textarea name="meta_key" type="text" id="meta_key" cols="50" rows="3"><?php echo $meta_key ?></textarea> </label> </p> <p> <label>Article Summary<br /> <textarea name="meta_desc" type="text" id="meta_desc" cols="50" rows="5"><?php echo $meta_desc ?></textarea> </label> </p> <input name="submit" type="submit" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/140792-solved-db-update-not-working-possibly-just-needs-a-2nd-pair-of-eyes/ Share on other sites More sharing options...
aschk Posted January 14, 2009 Share Posted January 14, 2009 You logic won't work because you're not populating the $pageID, $pageName, $articleTitle, $articleBody, $meta_key, $meta_desc variables in the elseif part of your statement. You're doing if (blah) populate variables (listed above) elseif(another blah) use variables populated... OOPS i haven't populated them in this part... Quote Link to comment https://forums.phpfreaks.com/topic/140792-solved-db-update-not-working-possibly-just-needs-a-2nd-pair-of-eyes/#findComment-736902 Share on other sites More sharing options...
Merdok Posted January 14, 2009 Author Share Posted January 14, 2009 Don't the variables come from the POST command? Quote Link to comment https://forums.phpfreaks.com/topic/140792-solved-db-update-not-working-possibly-just-needs-a-2nd-pair-of-eyes/#findComment-736903 Share on other sites More sharing options...
Merdok Posted January 14, 2009 Author Share Posted January 14, 2009 Well it worked anyway Cheers mate, I wonder how it worked the last few times I used it now though? Perhaps those websites were posessed by the Devil! Quote Link to comment https://forums.phpfreaks.com/topic/140792-solved-db-update-not-working-possibly-just-needs-a-2nd-pair-of-eyes/#findComment-736905 Share on other sites More sharing options...
aschk Posted January 14, 2009 Share Posted January 14, 2009 Yup they do come from the $_POST, but you're using them before you've populated from $_POST. see line: if (empty($articleTitle) || empty($articleBody) || empty($pageName) || empty($meta_key) || empty($meta_desc)) You've not set those variables yet Quote Link to comment https://forums.phpfreaks.com/topic/140792-solved-db-update-not-working-possibly-just-needs-a-2nd-pair-of-eyes/#findComment-736928 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.