Monday, 27 January 2020

Showing videos which are stored in Server using PHP

Hi All,
This code can be used to view videos which are stored in server.
Table contents are shown using reusable code here.
You have to change only the sql in the below given code.
No need to type the entire code.
Just copy and run.


-----------------------------------------------------------------------------------------------------------
<center>
<?php
include('connect.php');

$query = 'select * from upload';
$result = mysql_query($query);
if (!$result)
{
$message = 'ERROR:' . mysql_error();
return $message;
}
else
{
$i = 0;
echo '<html><body><table border=1 align=center><tr>';
while ($i < mysql_num_fields($result))
{
$meta = mysql_fetch_field($result, $i);
echo '<th>' . ucfirst($meta->name) . '</th>';
$i = $i + 1;
}
echo '<th>View</th></tr>';
$i = 0;
while ($row = mysql_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$y = 0;
$idval='1';
while ($y < $count)
{
$c_row = current($row);
if($y==0)
$idval=$c_row;
echo '<td>' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
echo '<td><a href=videoupload1/'.$idval.'.mp4>View Video</a></td>';
echo '</tr>';
$i = $i + 1;
}
echo '</table></body></html>';
mysql_free_result($result);
}
mysql_close ($con);

?></center>

Friday, 10 January 2020

Create a Hashtag with Auto Id

Hi All,
Using this code you can save data to a table with auto generated ID in PHP.

--------------------------
Table


CREATE TABLE IF NOT EXISTS `hashtag` (
  `hid` int(11) NOT NULL,
  `tag` text NOT NULL,
  `description` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


---------------------------

<html>
<body>
<?php

mysql_connect("localhost","root","");
mysql_select_db("tcsr");

$sql1="select max(hid) as mid from hashtag ";
$data1=mysql_query($sql1);

$id=0;

while($row=mysql_fetch_array($data1))
{


   $id=$row['mid'];
}
$id=$id+1;
echo $id;

?>
<form name="frm"   method=post enctype="multipart/form-data" >
<pre>
Id           <input type="text" value="<?php echo $id; ?>" disabled=disabled name="hid" /> <input  name="hid1" type="hidden" value="<?php echo $id; ?>" />
HashTag      <input type="text" name="hashtag" />
Description  <input type="text" name="description" />

<input name="hsubmit" type="submit" value="Upload files" />
</form>



<?php
echo "entered";
if(isset($_POST['hsubmit']))
{
echo "Entered";
$hid=$_POST['hid1'];
$hashtag=$_POST['hashtag'];
$desc=$_POST['description'];

$sql="insert into hashtag values('$hid','$hashtag','$desc')";
echo $sql;
$result=mysql_query($sql);

}

?>
</body>
</html>