Youtube Embed code stored in database not appearing in HTML Form

本小妞迷上赌 提交于 2020-01-06 20:35:01

问题


I have an UPDATE php page to edit a websites database that contains Youtube's embed code which then gets properly displayed when the table is called. On the update page im calling the same portion of the database to be able to change/edit the embed code but it is not displaying the original complete code only <iframe width= in the form.

<html>
<?
if (isset($_POST['update'])) {
?>

  <form method="post">
      Submitter: <input type="text" name="submitter" value="<?= $video['submitter'] ?>" /> <br />
      Video Title: <input type="text" name="videoTitle" value="<?= $video['videoTitle'] ?>" /> <br />
      Channel Name: <input type="text" name="channelName" value="<?= $video['channelName'] ?>" /> <br />
      Video Link: <input type="text" name="videoLink" value="<?= $video['videoLink'] ?>" /> <br />
      <input type="hidden" name="videoId" value="<?= $video['videoId'] ?>" />
      <input type="submit" value="Save" name="save" />  
  </form>

<?
  }//endIf
?>
</html>

回答1:


You have to use htmlentities to convert the quotes to HTML entities.

$str = htmlentities($str);

http://php.net/manual/en/function.htmlentities.php

Use it like this:

  <form method="post">
      Submitter: <input type="text" name="submitter" value="<?= $video['submitter'] ?>" /> <br />
      Video Title: <input type="text" name="videoTitle" value="<?= $video['videoTitle'] ?>" /> <br />
      Channel Name: <input type="text" name="channelName" value="<?= $video['channelName'] ?>" /> <br />
      Video Link: <input type="text" name="videoLink" value="<?= htmlentities($video['videoLink']) ?>" /> <br />
      <input type="hidden" name="videoId" value="<?= $video['videoId'] ?>" />
      <input type="submit" value="Save" name="save" />  
  </form>

Also if you are going to be saving this data into a database be sure to call html_entity_decode on the data being sent by the form before saving it to the database.



来源:https://stackoverflow.com/questions/23419051/youtube-embed-code-stored-in-database-not-appearing-in-html-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!