Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Wednesday, 10 July 2013

Facebook like and unlike system using [php-mysql-ajax] and facebook wall post system with time calculation system for each post and display it in users wall



We have to make Facebook wall system,Face book like system and Facebook time management system  for each and every post
-In my previous post Facebook wall system will be implemented
-In this Post contains facebook like system and facebook time management system along with wall post system  will be implemented
-in this section i have created separate login system for every users 
-users can login and post their words in their wall 
-others users will like or unlike the post using their user-id
-face book time management means, users posts display the time when they   posted and how many hours,minutes or seconds ago they posted their words or quotes and all
- this are the task we have to done 
-there are several steps to complete our task
-Create database and following tables 
-there are 3 Table contains in database

      1.Login
      2.Messages
      3.message_like

1.Login table :

CREATE TABLE IF NOT EXISTS `login` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  `password` varchar(250) NOT NULL,
  PRIMARY KEY (`uid`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;

2.Message table:

CREATE TABLE IF NOT EXISTS `messages` (
  `msg_id` int(11) NOT NULL AUTO_INCREMENT,
  `message` varchar(200) NOT NULL,
  `uid_fk` int(11) NOT NULL,
  `like_count` int(11) DEFAULT NULL,
  `created` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`msg_id`),
  KEY `uid_fk` (`uid_fk`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

3.message_like table :


CREATE TABLE IF NOT EXISTS `message_like` (
  `like_id` int(11) NOT NULL AUTO_INCREMENT,
  `msg_id_fk` int(11) DEFAULT NULL,
  `uid_fk` int(11) NOT NULL,
  `created` varchar(250) NOT NULL,
  PRIMARY KEY (`like_id`),
  KEY `uid_fk` (`uid_fk`),
  KEY `msg_id_fk` (`msg_id_fk`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=59 ;

-Download the file and configure your hostname,username and password
-Live demo is available,check it 
- if any queries regarding, post your commands





Screen Shots:


















Saturday, 6 July 2013

A simple hotel booking software using [php-mysql-ajax]


Description:

We have to create simple hotel booking software using php,mysql

-there are several process to done the above task .
-first of all create the database for hotel booking system
-database contains 4 tables
     1.booking
     2.Customer
     3.invoice
     4.room
-booking table contains (id,arraival,checkout,room,customerid,cotrequire,satelliterequire,gamrequire,service)
-customer table contains(id,firstname,lastname,email,address,city,state,pincode,phone)
-invoice table contains(id,cusmail,chkout,roomno,roomtype,price,total etc..)
-room table contains (id,roomnum,type,price ,etc..)
-download this software
-install wamp software
-import database from download file in phpmyadmin
-configure and run it ..

screen shots:








Download

Friday, 5 July 2013

Dynamic Chat Design for android and ios



Description:

-Dynamic chat ui ll be created for android and ios mobiles.
-Dynamic chat ui created by using HTML5 and CSS3 technologies.
-It is very easy to integrate it.
-Systematic Explain will be done .
-Just download and use it. 
-Download file contains[chat.html,chatcs.css,battery.png,signal.png,wifi.png]
-If any queries please post your commands  !. 

Output will be :


Download

Tuesday, 2 July 2013

cURL-tutorial startup


cURL:
         1.cURL is a Command line tool for getting and sending datas through URL 
         
Now we can display the Google webpage with search key word "technoblazze" in your server by using cURL
We have to Follow 4 steps to do the above task
1.initialize the curl session
2.set various option for the session
3.Execute the option, fetch and display the datas in your server
4.close the curl session
curl.php
<?php 
$curl = curl_init('http://www.google.com/search?q=technoblazze.blog'); //step1
curl_setopt($curl, CURLOPT_FAILONERROR, true);    //step2
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   
$result = curl_exec($curl);                       //step3
curl_close($curl);                                //step4
echo $result;
?>
Download

Tuesday, 18 June 2013

Print the Report or Page using Javascript And PHP


Javascript file:
<script>
function printDiv(id)
{
  var divToPrint=document.getElementById(id);
  newWin=window.open('', '', 'left=5,top=10,width=1024,height=768,toolbar=0,scrollbars=0,status=0');
  var str='<html><head><link href="css/css.css" rel="stylesheet" type="text/css"/></head><body><div align="center"><img src="image/logo.png" border="0"></div><br/><div align="center"><b>Outstanding Report</b></div><br></body></html>';
  newWin.document.write(str);
  newWin.document.write(divToPrint.outerHTML);
  newWin.print();
  newWin.close();
}
</script>

Passing the Div ID parameter:
<input type="image" onClick="return printDiv('sprint');"  value="print"  src="image/printj.png" class="flrt" title="print report"/>
<div id="sprint">
<?php
// Dynamic Code here
?>
</div>
Expected Output:

Saturday, 15 June 2013

Script for Dynamic MORE or LESS and [all the DIV's become Less when One more option is clicked]

<script>
 $(document).ready(function () {
var showChar = 100;
 var ellipsestext = "...";
 var moretext = "more";
 var lesstext = "less";
 var txtlen = 1;
 $('.more').each(function () {
 var content = $(this).html();
 if (content.length > showChar) {
 var c = content.substr(0, showChar);
 var h = content.substr(showChar - 1, content.length - showChar);
 var html = c + '<span class="moreelipses">' + ellipsestext + '</span>&nbsp;<span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink" id=testimonial' + txtlen + '>' + moretext + '</a></span>';
$(this).html(html);
 }
 txtlen++;
 });
 $(".morelink").click(function () {
 if ($(this).hasClass("less")) {
 $(this).removeClass("less");
$(this).html(moretext);
 } else {

 for (var i = 1; i < txtlen; i++) {
if ($("a#testimonial" + i).attr('class') == "morelink less")
 {
 $("a#testimonial" + i).trigger("click");
 }
 }
 $(this).addClass("less");
 $(this).html(lesstext);
}
 $(this).parent().prev().toggle();
 $(this).prev().toggle();
 return false;
 });
 });
</script>

<div class="comment more">
 <?php 
              //give dynamic code
        ?>
</div>
<div class="comment more">
 <?php 
              //give dynamic code
        ?>
</div>

Sunday, 9 June 2013

Face book Wall Post



Index.php:

<?php
include 'class.php';
$db=new database();
$db->connect();
?>
<link rel="stylesheet" href="wall.css" type="text/css" />
<script type="text/javascript" src="jquery-latest.js"></script>
<script>
$(document).ready(function() {
$('#textpost').click(function() {
      var b=$("#fbpost").val();
      var dataString = 'fbwall='+b;
      $.ajax( {
              type:"POST",
      		async: false,
              url:"ajax.php",
              data: dataString,
              success: function(data) {		

			  	  $("#fbpost").val("");		 
                  $("#viewpost").html(data);				  				             
              }
          });
});
});

</script>
<div id="container">
	<div>
    <img src="facebook-logo.jpg" width="200" height="75"/>
    </div>
	<div id="post">
    	<form action="" method="post">
        	<p class="example-twitter">
        	<textarea name="fbwall" id="fbpost" class="" placeholder="whatzz upp?" >
            </textarea>               
            <br/>  <br/> 
            <a href="#" class="button postfb" id="textpost">Post</a>
            </p>
        </form>                      
    </div>
    <br><br><br><br>
    <div id="viewpost">
    <?
	$queyr=$db->query("select * from fb ORDER BY `id` DESC");
	while($query=$db->fetch($queyr))
	{
	?>
    <div id="display">
    	<div id="leftdisplay">
        <img src="http://lh3.googleusercontent.com/-Iw_xOyvn0z0/AAAAAAAAAAI/AAAAAAAAAFw/r_0QqjeH2vQ/s512-c/photo.jpg"  width="120" height="120"/>
        </div><br/><br/>
        <div id="rightdisplay">
        	<p class="triangle-border left">
            	<? echo $query["wallpost"];?>
            </p>
        </div>
    </div>
    <div style="height:200px;"></div> 
    <? } ?>   
    </div>
</div>


Ajax.php:

<?
include 'class.php';
$db=new database();
$db->connect();
if(isset($_REQUEST["fbwall"]))
{
	$wall=$_REQUEST["fbwall"];
	$insert=$db->query("INSERT INTO fb (wallpost) VALUES ('$wall')");
	if($insert)
	{
		$select=$db->query("select * from fb ORDER BY `id` DESC");
		while($view=$db->fetch($select))
		{?>
             <div id="display">
                <div id="leftdisplay"><img src="http://lh3.googleusercontent.com/-Iw_xOyvn0z0/AAAAAAAAAAI/AAAAAAAAAFw/r_0QqjeH2vQ/s512-c/photo.jpg"  width="120" height="120"/></div><br/><br/><br/><br/>
                <div id="rightdisplay">
                    <p class="triangle-border left">
                        <? echo $view["wallpost"];?>
                    </p>
                </div>
            </div>
            <div style="height:200px;"></div>
		<? }
	}
}
?>

Database:
id---------->int(11)
wallpost--->longtext()

class.php
<?

class database

{
	 public function connect()
     {

        $con=mysql_connect("localhost","root","") or die("unable to connect");
        mysql_select_db("test",$con) or die("unable to select");
     }
     public function query($sql)
     {
         $sc=mysql_query($sql) or die("query not working".  mysql_error());
         return $sc;
        
     }
     public function  fetch($qu)
     {
         $ft=mysql_fetch_array($qu);
         return $ft;
     }
     public function num($rows)
     {
         $rw=mysql_num_rows($rows);
         return $rw;
       
     }
}
?>

Output:

Download

Thursday, 6 June 2013

Dynamic Autocomplete using php

index.php:<
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto Complete Input box</title>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.autocomplete.js"></script>
<script>
$(document).ready(function(){
 $("#tag").autocomplete("autocomplete.php", {
  selectFirst: true
 });
});
</script>
</head>
<body>
<label>Tag:</label>
<form action="" method="post">
<input name="tag" type="text" id="tag" size="20"/> 
 <input type="submit" value="submit" name="gt"/>
<form>
</body>
<?php
if(isset($_POST["gt"]))
{
$mysql=mysql_connect("localhost","root","123");
mysql_select_db("hi",$mysql);
mysql_query("insert into tag (name) values ('".$_POST["tag"]."')");
echo $_POST["tag"];
}
?>
</html>
autocomplete.php:
<?php
 $q=$_GET['q'];
 $my_data=mysql_real_escape_string($q);
 $mysqli=mysqli_connect('localhost','root','123','hi') or die("Database Error");
 $sql="SELECT name FROM tag WHERE name LIKE '%$my_data%' ORDER BY name";
 $result = mysqli_query($mysqli,$sql) or die(mysqli_error());
 
 if($result)
 {
  while($row=mysqli_fetch_array($result))
  {
   echo $row['name']."\n";
  }
 }
?>


Database :
id--->int(4)--->Autocomplete
Name--->varchar(50)
Download

Tuesday, 23 April 2013

CRUD operation using checkbox in PHP


<!--jquery for check box selecting  -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function ()
{
$('#d').click(function()
{
if (this.checked==true)
{
$('input[name="a[]"]').prop('checked', true);
}
if (this.checked==false)
{

$('input[name="a[]"]').prop('checked', false);
}
});
});
</script>
<!--new registeration form -->
Register here !!
<form action="" method="post">
username : <input type="text" name="uname"/></br>
password : <input type="password" name="pas"/></br>
Postion  :<input type="text" name="pos"/></br>
<input type="submit" value="register" name="reg"/>
</form>
<!--new chk box editing-->
<?php
$cn=mysql_connect("localhost","root","123");
mysql_select_db("hotel",$cn);
$wue=mysql_query("select * from user");
echo '<form action="" method="post">';
?>
<!--Displaying db values with check box-->
<table>

<tr>
<td><input type="checkbox" name="act" value="" id="d"></td>
<td>ID</td>
<td>USERNAME</td>
<td>POSITION</td>
</tr>
<?php
while($row=mysql_fetch_array($wue))
{
?>
<tr>
<td>
<input type="checkbox" name="a[]" value="<?php echo $row['user_id'];?>"></td>
<?php<
echo '<td>'.$row['user_id'].'</td>';
echo '<td>'.$row['username'].'</td>';
echo '<td>'.$row['position'].'</td>';
echo '</tr>';
}
?>
</table>
<?php
echo '<input type="submit" name="subval" value="edit"/>'.'<input type="submit" name="subdelete" value="delete"/>'.'</form>';
//check box selected value will be displayed in text box
if(isset($_POST['subval']))
{
$ar=$_POST['a'];
echo '<form action="" method="post">';
foreach($ar as $ty)
{
$ru=mysql_query("select * from user where user_id='$ty'");
$ew=mysql_fetch_array($ru);
?>
username :<input type="text" value="<?php echo $ew['username'];  ?>" name="name<?php echo $ty ?>"/>
Position :<input type="text" value="<?php echo $ew['position']; ?>" name="pos<?php echo $ty ?>"/>
<input type="hidden" name="id[]" value="<?php echo $ew['user_id']; ?>">
</br>
<?php
}
echo '<input type="submit" name="subupdate" value="update"/>'.'</form>';
}
//update the text box value after editing
if(isset($_POST['subupdate']))
{
$u=$_POST['id'];
foreach($u as $i)
{
$updt=mysql_query("update user set username='".$_POST['name'.$i]."' , position='".$_POST['pos'.$i]."' where user_id='$i'");
if($updt)
{
echo '<script>window.location=""</script>';
}
}
}
//delete the selected values by using check box
if(isset($_POST['subdelete']))
{
$uio=$_POST['a'];
foreach($uio as $yu)
{
$delt=mysql_query("delete from user where user_id='$yu'");
if($delt)
{
echo '<script>window.location=""</script>';
}
}
}
if(isset($_POST['reg']))
{
$insr=mysql_query("insert into user ( `username`, `password`, `position`) values('".$_POST['uname']."','".$_POST['pas']."','".$_POST['pos']."')");
if($insr)
{
echo '<script>window.location=""</script>';
}
}
?>

OUTPUT:
Download

Thursday, 18 April 2013

Display number of Files in a Folder using PHP

<?php
   $path = "d://songs/2013 songs";
   // Open the folder
   $dir_handle = @opendir($path) or die("Unable to open $path");
   // Loop through the files
   while ($file = readdir($dir_handle))
   { 
    echo "<a href=\"$file\">$file</a><br />";
   }
   closedir($dir_handle);
?>

Download

Saturday, 16 March 2013

Image upload and retrieve in a Binary method using php and mysql

Inserting Image 
<?php

// Create MySQL login values and
// set them to your login information.

$username = "root";
$password = "123";
$host = "localhost";
$database = "test";

// Make the connect to MySQL or die
// and display an error.

$link = mysql_connect($host, $username, $password);

if (!$link)
 {
    die('Could not connect: ' . mysql_error());
 }
// Select your database
mysql_select_db ($database);
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0)
 {
      // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name']; 
      // Read the file
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);


      // Create the query and insert
      // into our database.
      $query = "INSERT INTO tbl_images ";
      $query .= "(image) VALUES ('$data')";
      $results = mysql_query($query, $link);
      // Print results
      print "Thank you, your file has been uploaded."; 
}
else
{
     print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close($link);
?> 
Displaying Images
<?php
$username = "root";
$password = "123";
$host = "localhost";
$database = "test";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$query = mysql_query("SELECT * FROM tbl_images");
while($row = mysql_fetch_array($query))
{
echo '<img src="data:image/jpg;base64,'.base64_encode($row['image']).'" /><br /><br /><br />';
}
?>

Download

Thursday, 7 March 2013

mail Attachement in php


<?php
if(isset($_POST['Submit'])) 
   {
    $from=$_POST['uname'];

    $t=$_POST['email'];
    $y=$_POST['post'];
    $rr=$_FILES['file']['strresume'];
    $to="letters/".$_FILES['strresume']['name'];
    move_uploaded_file($_FILES['strresume']['tmp_name'],$to);
    $fileatt = "letters/".$_FILES['strresume']['name']; // Path to the file
    $fileatt_type = "application/octet-stream"; // File Type
    $fileatt_name = "CV_".$_FILES['strresume']['name']; // Filename that will be used for the file as the attachment
    $email_from = $_POST['nume']." ".$_POST['prenume']; // Who the email is from
    $email_subject = "CV".$_FILES['strresume']['name']; // The Subject of the email
    //here you define the body of the message, the message itself
    //you can modify the "post" textfield in sendmail.php to a textarea....
    $email_message ="Name:".$from;
    $email_message.="\r\n";
    //$email_message.=$_POST['uname'];
    $email_message.="Email:".$_POST['email'];
    $email_message.="\r\n";
   //$email_message.="Post Applied For:"
    $email_message.="Post Applied For:". $_POST['post']; // Message that the email has in it
    //here you enter the e-mail address to wich you want the message to be sent
    $email_to = " vivekamcbseschool@gmail.com"; // Who the email is too
    //adds the e-mail address of the sender
    $headers = "From: ".$_POST['email'];
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers .= "\nMIME-Version: 1.0\n" .
      "Content-Type: multipart/mixed;\n" .
      " boundary=\"{$mime_boundary}\"";
      $email_message .= "This is a multi-part message in MIME format.\n\n" .
       "--{$mime_boundary}\n" .
        "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
        "Content-Transfer-Encoding: 7bit\n\n" .
        $email_message . "\n\n";

        /********************************************** First File ********************************************/


      //$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload

      $fileatt = "letters/".$_FILES['strresume']['name']; // Path to the file
      $fileatt_type = "application/octet-stream"; // File Type
      //here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
      //i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now :D
      $fileatt_name = "CV".$_FILES['strresume']['name']; // Filename that will be used for the file as the attachment
      $file = fopen($fileatt,'rb');
      $data = fread($file,filesize($fileatt));
      fclose($file);
      $data = chunk_split(base64_encode($data));
      $email_message .= "--{$mime_boundary}\n" .
      "Content-Type: {$fileatt_type};\n" .
      " name=\"{$fileatt_name}\"\n" .
      //"Content-Disposition: attachment;\n" .
      //" filename=\"{$fileatt_name}\"\n" .
      "Content-Transfer-Encoding: base64\n\n" .
      $data . "\n\n" .
      "--{$mime_boundary}\n";
      unset($data);
      unset($file);
      unset($fileatt);
      unset($fileatt_type);
        unset($fileatt_name);

        /********************************************** End of File Config ********************************************/

      // To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work!
      $ok = @mail($email_to, $email_subject, $email_message, $headers);
      if($ok) {?>
      <script>
       alert("Thanks for applying at Vivekam careers! will get back to you soon!");
       window.location="careers.php";
      </script>
      <?php } 
   }

   ?> 





Sunday, 10 February 2013

AJAX-JQUERY-PHP


<script type="text/javascript">
function searchNow() { 
var a=$("#h").val();
var b=$("#hi").val();
var dataString = 'name='+ a + '&namei=' + b;
//your validation code
$.ajax( {
        type:"POST",
async: false,
        url:"register.php",
        data: dataString,
        success: function(data)
{
alert("test");
        $("#message").html(data);
        }
    } );
}
</script>
<input type = "text" name = "name" id="h">
<input type = "text" name = "namei" id="hi" >
<input type = "button" name = "name" id="i" onClick="searchNow();">
<div id="message"></div>
//in regisrer.php:
$a=$_POST['name'];
$b=$_POST['namei'];
echo $a;
echo "<br>";
echo $b;

Download

Thursday, 13 December 2012

Admin panel for uploading & retrieving image by using folder in PHP

Css for Adminpanel .php:


#container{ width:700px; margin:0 auto 0 auto;}
#main{ width:700px; height:500px;}
#main0{ width:200px; height:500px; float:left;}
#main1{ width:500px; float:left; height:500px; background:url(images/back.png);}
.pad{ padding-left:100px;}
.fnt{ font-size:25px; font-family: Tahoma, sans-serif; color:#3490b7;}
.lab{ float:left; width:30%; text-align:right; margin-right:15px;}
#frm{ padding-left:100px;}
.text{padding: 5px;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-left: 5px;
width: 180px;
font-family: Helvetica, sans-serif;
font-size: 1.4em;
margin: 0px 0px 10px 0px;
border: 2px solid #CCC;}
.submit{-webkit-box-align: center;
text-align: center;
cursor: default;
color: buttontext;
padding: 2px 6px 3px;
border: 2px outset buttonface;
border-image: initial;
background-color: buttonface;
box-sizing: border-box;
padding: 5px;
width: 80px;
font-family: Helvetica, sans-serif;
font-size: 1.2em;

border: 2px solid #CCC;
}
.fontad{font-family: Helvetica, sans-serif;
font-size: 1.2em;}
.imgpad{ padding-left:150px;}

Admin-panel.php:


<div id="container">
<div id="main ">
    <div id="main0"><img src="images/admin.png" /></div>
        <div id="main1">
        <div id="wel">
            <p class="pad fnt">Welocome To Admin Panel !!!</p>
            </div>
            <div class="imgpad"><img src="images/admin123.png"  /></div>
            <div id="frm">
            <form action="adminpanel.php" method="post">
                <label class="lab fontad">Admin-Name</label>
                    <input type="text" name="admin" class="text" /><br /><br />
                     
                    <label class="lab fontad">Password</label>
                    <input type="password" name="pass" class="text" /><br /><br />
                    <div style="padding-left:250px;"><input type="submit" name="submit1" class="submit" /></div>
                </form>
            </div>
        </div>
    </div>
</div>


<?
if(isset($_POST['submit1']))
{
$a=$_POST['admin'];
$b=$_POST['pass'];
if($a=="admin" && $b=="admin")
{?>
<script> window.location="admin.php" </script>
<? }
else
{?>
<script> alert("please enter valid username & password")</script>
<? }
}
?>


in admin.php:


<form action="upload.php" method="post" enctype="multipart/form-data" >
<input type="hidden" name="upload" value="1" />
<input type="file" name="file" id="file" class="validate[required] text-input text" /><br /><br />
<div style="padding-left:250px;"><input type="submit" name="btnSubmit" value="Submit" class="button3 orange button_wid submit" /></div>
</form>


in upload.php:


 <?php
if($_POST[upload]==1)
{  
  $to="upload/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$to);
 
  echo '<img src="'.$to.'">';
}

?>












Thursday, 25 October 2012

php for youtube upload by using url


<form action="tube.php" method="post">
<input type="text" name="id" />
<input type="text" name="you" />
<input type="submit" value="submit" />
</form>
<?php  $con=mysql_connect("localhost","root","");
mysql_select_db("tube",$con);
$long = $_POST['you'];
$id = $_POST['id'];
mysql_query("INSERT INTO `youtube`(`id`, `url`) VALUES ('$id','$long')") or die("unable to connect");
$query=mysql_query("SELECT `id`, `url` FROM `youtube` where `id`=1");
while($res=mysql_fetch_array($query))
{
   
?>
<?php

$longString = $res['url'];
$len=strlen($longString );

?>
<?php
if($len>43)
{
 ?>
<iframe width="560" height="315"  id="cs" src="
<?php


$b = substr($longString , strpos($longString , 'watch?v') + 1);


$c = substr($b, 0, strpos($b, '&'));

$str2 = substr($c, 7);


/*
echo substr_replace($c, '', 15) . "<br />\n";
echo "<br>";
$d = substr($a, 0, strpos($a, '='));
print $d; // prints 9999 */

$mn=substr_replace($longString , 'embed/', 23);

$mn .=$str2;

echo $mn;





?>" frameborder="0" allowfullscreen></iframe><?php } else {?>


<?php

$separator = 'embed/';
$separatorlength = strlen($separator) ;
$maxlength =53 - $separatorlength;
$start = $maxlength / 2 ;
$trunc =  strlen($longString) - $maxlength;

$st= substr_replace($longString, $separator, $start);
echo "<br>";
$st.=substr($longString,31);




?>
<iframe width="560" height="315" src="<?php echo $st; ?>" frameborder="0" allowfullscreen></iframe><?php } ?> <br /><br /><br /> <?php }?>