GKWelding Posted December 30, 2008 Share Posted December 30, 2008 Simple if statement causing me problems. Been looking at this too long to figure it out now so I'm not even going to try anymore as it's all just starting to merge into one which means I'm just wasting my time. Ok, so I have a form linked to this script. You put in the title, and the text. hit submit and it posts info to the db for display later on, simple blog. However, hitting post even when you have text in the title and body causes the loop to spit out 'You must enter and entry title and entry text.' however it also posts the data to the database correctly as it should do. So basically it's getting the message from the first part of the if loop whilst doing the action of the else part of the if loop. Any suggestions? $entryTitle = $_POST['entryTitle']; $entryText = $_POST['entryText']; $blogId = $_POST['blogId']; $userId = um()->getCurrentUser()->getUserId(); $myblog = blogconc()->getOneBlog($userId); $blogOwner = $myblog->getBlogOwner(); if($blogOwner != $userId){ $message = "You do not have permission to add to this blog"; } else { if (trim($entryTitle) == "" && trim($entryText) == ""){ $message = "You must enter and entry title and entry text."; } else { $blogcheck = blogconc()->getOneBlog($userId); $blogcheckid = $blogcheck->getBlogId(); if ($blogcheckid != ""){ $entryBlogId = $blogcheckid; $query = blogconc()->addEntry($entryBlogId, $entryTitle, $entryText); //if ($query){ $message = "Entry Added Successfully!"; //} } else { $message = "You are trying to post to a blog that doesn't exist."; } } } Quote Link to comment https://forums.phpfreaks.com/topic/138879-simple-if-problem/ Share on other sites More sharing options...
Mark Baker Posted December 30, 2008 Share Posted December 30, 2008 If the database is updating correctly, then the issue may be what you're doing afterwards, in the code that you haven't posted here. e.g. If you're redirecting back to this script to run it a second time, without the post vars. Quote Link to comment https://forums.phpfreaks.com/topic/138879-simple-if-problem/#findComment-726220 Share on other sites More sharing options...
GKWelding Posted December 30, 2008 Author Share Posted December 30, 2008 I thought that too, so I put a further if statement around $message = "You must enter and entry title and entry text."; that said if $_POST isn't set then do not populate with this text, but alas that didn't work... Still got the same error. Quote Link to comment https://forums.phpfreaks.com/topic/138879-simple-if-problem/#findComment-726222 Share on other sites More sharing options...
premiso Posted December 30, 2008 Share Posted December 30, 2008 I highly doubt this is possible but one possible solution is: $entryTitle = $_POST['entryTitle']; $message = ""; Make sure the message is defaulted to "". What may be happening, is possibly session or cookie or get or post is populating the message (if register_globals) is on. So it may not contain the error it just carried it over on accident. Without seeing the full code, that is my best guess. Quote Link to comment https://forums.phpfreaks.com/topic/138879-simple-if-problem/#findComment-726229 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.