user1439090
user1439090

Reputation: 812

String separated by space in value field breaking when entered as a variable

I have a variable called $value in php which has a string value. When I echo this $value, I can see the entire string. However, when I pass it in the value field in html textbox, I can only see the first word of the string. Following is the code:-

$check = '<input type="checkbox" name="transcript'.$i.'" value=0 '.$checked.' />';
$value = $DB->get_field('course_completions', 'REMARKS', array ('course'=>$course->id, 'userid'=>$this->user->id), $strictness=IGNORE_MISSING);
$remark = '<input type="text" name="remark'.$i.'" value ='.$value.' size="30"/>';

Example:-> if $value is a string called "First comment", I can only see "First" in the textbox in html and the html code that gets generates looks like:-

<input type="text" name="remark1" value="First" comment="" size="30">

Can someone help me with this issue?

Upvotes: 0

Views: 1504

Answers (2)

Shubham Pendharkar
Shubham Pendharkar

Reputation: 330

You can simply write:

$remark = '<input type="text" name="remark'.$i.'" value ="'.$value.'" size="30"/>'; 

Upvotes: 0

Robbie
Robbie

Reputation: 17710

Change

 $remark = '<input type="text" name="remark'.$i.'" value ='.$value.' size="30"/>'; 

to

$remark = '<input type="text" name="remark'.$i.'" value ="'.htmlspecialchars($value).'" size="30"/>'; 

Upvotes: 2

Related Questions