Jump to content

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

Link to comment
https://forums.phpfreaks.com/topic/138879-simple-if-problem/#findComment-726222
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

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.