Jump to content

Problem with htmlentities


doubledee

Recommended Posts

I can't seem to get htmlentities working in the code below...

echo "<textarea id=\"question" . $questionNo . " name=\"qaArray[\"answerText\"]\" cols=\"60\" rows=\"2\">" .
	(isset($questionNo) ? "htmlentities($qaArray[\"answerText\"], ENT_QUOTES" : "") .
	"</textarea>";

 

I tried using the default single quotes around answerText but that doesn't, nor do my escaped double quotes.

 

What is wrong?

 

Thanks,

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/
Share on other sites

I can't seem to get htmlentities working in the code below...

   echo "<textarea id=\"question" . $questionNo . " name=\"qaArray[\"answerText\"]\" cols=\"60\" rows=\"2\">" .
      (isset($questionNo) ? "htmlentities($qaArray[\"answerText\"], ENT_QUOTES" : "") .
      "</textarea>";

 

I tried using the default single quotes around answerText but that doesn't, nor do my escaped double quotes.

 

What is wrong?

 

Thanks,

 

 

Debbie

 

 

Look at the syntax highlighting

 

 

   echo '<textarea id="question' . $questionNo . '" name="'. $qaArray['answerText'] .'" cols="60" rows="2">' .
      (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : '') .
      '</textarea>';

How does this look...

<?php
	foreach($thoughtsArray as $questionNo => $qaArray){
		echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>';
		echo '<textarea id="question' . $questionNo . '" name="' . $qaArray["answerText"] . '" cols="60" rows="2">';
		echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : '');
		echo '</textarea>';
	}
?>

 

It seems to run okay.

 

 

Debbie

Actually, the textarea NAME should be the ID or are you using the actual question text as the identifier for the textarea on processing?

<?php
foreach($thoughtsArray as $questionNo => $qaArray){
echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>';
echo '<textarea id="question' . $questionNo . '" name="' . $qaArray['questionID'] . '" cols="60" rows="2">';
echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : '');
echo '</textarea>';
}
?>

EDITED

Actually, the textarea NAME should be the ID or are you using the actual question text as the identifier for the textarea on processing?

<?php
foreach($thoughtsArray as $questionNo => $qaArray){
echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>';
echo '<textarea id="question' . $questionNo . '" name="' . $qaArray['questionID'] . '" cols="60" rows="2">';
echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : '');
echo '</textarea>';
}
?>

EDITED

 

As I see it, this is how things should look...

<?php
	foreach($thoughtsArray as $questionNo => $qaArray){
		// Build Question.
		echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . "\n";

		// Build Answer.
		echo '<textarea id="question' . $questionNo . '" name="' . $qaArray["questionID"] . '" cols="60" rows="2">';
		echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : '');
		echo "</textarea>\n\n";
	}
?>

 

Yes, I changed name=$qaArray['question'] because that is what uniquely identifies a Question, and it is needed to write the Answer into the "answer" table...

 

 

Debbie

 

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.