Jump to content

Saving into JSON slashing the content


Adamhumbug

Recommended Posts

Hi All,

I have a function:

function createContentBlock($pdo, $contentBlockType, $textBlockTitle, $textBlockContent)
{
	$portalId = $_GET['portalId'];
	$json = array(
		"Name" => $textBlockTitle,
		"Content" => $textBlockContent
	);
	$sql = "UPDATE portal_content 
			set portal_content_json = 
				JSON_SET(
					portal_content_json,'$.\"Portal Content\".\"Pages\".\"Home\".\"Content Block\"', :json)
			WHERE portal_attachment_id = :portalId";



	$stmt = $pdo->prepare($sql);
	$stmt->execute([
		':portalId' => $portalId,
		':json' => json_encode($json, JSON_UNESCAPED_SLASHES)
	]);
	return "Content Block Created";
}

When the data is going into the json, it looks like this:

"Content Block": "{\"Name\":\"asa\",\"Content\":\"<p>asa</p>\"}"
      },

You will see that it is also getting an additional closing bracket.

I dont know why it is going in like this as i have another function that is putting data in in the same way without this issue.

Link to comment
Share on other sites

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.