hiii

i want to share a video link from youtube in textarea and show on the div ,when im share embeded code from youtube it showed on the div but when im share the link ,it only show the link so how i ll i share link in same way as embedeb code ??

<?php
(isset($_SESSION['email_id']))
{
  echo $_SESSION['email_id'];
  $u_id=$_SESSION['email_id'];
}
  $sql="select * from post where post_id='$user_id'";
$result=mysql_query($sql);
$total_description=mysql_num_rows($result);
//$user_id=$_SESSION['email_id'];
 while($row=mysql_fetch_array($result))
    { $description=$row['description'];
     //$user_name=$row=['fname'];
      $user_name=$row['name'];
      $user_lname=$row['lname'];
      $user_email=$_SESSION['email_id'];
     } 
$description="";
if(isset($_POST['submit']))
{
$date=@date('Y-m-d H-i-s');
$description=$_POST['description'];$_SESSION['email_id']=$user_id;
$user_name=$row['name'];
$user_lname=$row['lname'];
$post="INSERT INTO `post`(`post_id`,`comment_id`,`user_id`,`description`,`date`) VALUES(NULL,0,'$user_id','$description','$date')";
 $result1=mysql_query($post);
 //echo $result;
 if(!$result)
 {
  die(mysql_error());
 }
}
?>


//and the div where it show
<div class="posted">
       <?php  echo "$user_name"." "."$user_lname";?>
        <?php echo $description;?> 


            </div>

Dani AI

Generated

Short version: detect YouTube URLs in the textarea, extract the video identifier, store that identifier (not raw iframe HTML) and generate the embed when you render the post. The reason you currently see a plain link is that the description is being output as text (or HTML-escaped) instead of being parsed into an embed. is right to suggest storing the identifier — that makes it easy to change dimensions, add lazy-loading, or switch provider logic later.

A robust approach is:

  • On submit, scan the posted text for YouTube links and extract the 11-character video id.
  • Validate the id (allowed chars and length), then store the id (and optionally the original text) in the DB.
  • When showing the post, generate the embed only for validated ids; keep the rest of the text HTML-escaped.

Example extractor (PHP):

if (preg_match('/(?:youtu\.be\/|youtube\.com\/(?:watch\?v=|embed\/|v\/))([A-Za-z0-9_-]{11})/', $text, $m)) {
    $video_id = $m[1]; // use this id for storage/display
}

Security and UX notes: use prepared statements (PDO or mysqli) instead of deprecated mysql_* functions; do not store untrusted HTML; only output embed markup for IDs you have validated. For better performance and safety, show a thumbnail (or a lightweight placeholder) and replace it with the player on click (lazy-load). Consider using a content security policy and an HTML sanitizer/allowlist so normal text remains safe.

Troubleshooting: if links still show as plain text, check the order of operations (parse and replace before escaping, or escape only non-embed parts), verify the value actually saved to the DB, and test with different YouTube URL variants. For , start by adding the extractor step before insertion and move away from storing raw embed code; that will fix maintainability and XSS concerns.

Member Avatar for Member #120589

You can set up your table to just hold the video identifier, e.g. Ujwod-vqyqA
You can then build the embed link dynamically through php.

$videoframe = "<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/$video_id\" frameborder=\"0\" allowfullscreen></iframe>";

This has the advantage of not having to update ALL your video embed codes in a table if you want to change say the dimensions or if, perish the thought, YT decide to change the format of its embed code (can't see that happening though).

Example:

VIDEOS TABLE

video_id [32]
video_identifier [Ujwod-vqyqA]
video_type_id [2]

EMBED_CODES TABLE

video_type_id [2]
video_supplier [YouTube]
embed_code [<iframe width="560" height="315" src="http://www.youtube.com/embed/#VIDEO#" frameborder="0" allowfullscreen></iframe>]

You then replace the #VIDEO# string with video_identifier, e.g. str_replace()

BTW:
Your import code for the textarea can strip the embed code to leave just the video_identifier before inserting it into the DB. You could use regex for this (based on the 'src=').

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.