Jump to content

Simple IF Problem


GKWelding

Recommended Posts

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.";
			}

		}
	}

Link to comment
https://forums.phpfreaks.com/topic/138879-simple-if-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/138879-simple-if-problem/#findComment-726229
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.