Enter Keyword Hear for Search This Blog

Saturday, 23 April 2016

String function in php

echo

<?php
echo " A value is ";
$a=4;
echo $a;
?>


chr

<?php
echo chr(65);
echo "<br/>";
echo chr(122);
?>


strlen

<?php
$pwd="abc@123";
if(strlen($pwd)<6)
{
echo "password to short";
}
?>


ord

<?php
echo ord(' ');
echo "<br/>";
echo ord('z');
?>

print

<?php
print " A value is ";
$a=4;
print $a;
?>

strtoupper

<?php
echo strtoupper('hello');
echo "<br/>";
echo strtoupper('world');
?>

strtolower

<?php
echo strtolower('HEllo');
echo "<br/>";
echo strtolower('WORLD');
?>


substr

<?php
$a="harsukh k k";
$b=strlen($a);
for($i=0;$i<=9;$i++){
$j=substr($a,$i,1);
$d=ord($j);
echo $d;
echo"<br />";
echo $j;
}


?>

chop

<?php
     $str = "Hello World!";
     echo $str . "<br>";
     echo chop($str,"World!");
?>

join

<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo join(" ",$arr);
?>

parse_str

<?php
parse_str("name=Peter&age=43");
echo $name."<br>";
echo $age;
?>

How to create pagging system using php

view_pagging.php

<?php

$link=mysql_connect("localhost","root","");

mysql_select_db("product",$link);

$page_q="select * from mobile";

$page_res=mysql_query($page_q,$link); 

$item=3;
$total_record=mysql_num_rows($page_res);
$total_page=ceil($total_record/$item);
$cur_page=(isset($_GET['page']))?$_GET['page']:1;
?>
<html>
<body>
<table border="1" width="50%" align="center">
<tr>
<th>No</th>
<th>Name</th>
</tr>

<?php

$k=($cur_page-1)*$item;

$q="select * from mobile LIMIT $k,$item";

$res=mysql_query($q,$link);

while($row=mysql_fetch_array($res))
{
echo '<tr align="center">
<td>'.$row['id'].'
<td>'.$row['nm'].'
</tr>';
}
?>
</table>

<center>
<?php
if($cur_page>1)
{
echo '<a href="view_pagging.php?page='.($cur_page-1).'">Previous </a>';
}
else
{
echo 'Previous';
}

for($i=1;$i<=$total_page;$i++)
{
echo '<a href="view_pagging.php?page='.$i.'">'.$i.'</a> ';
}

if($cur_page<$total_page)
{
echo '<a href="view_pagging.php?page='.($cur_page+1).'">Next</a>';
}
else{
echo 'Next';
}
?>
</center>
</body>
</html>

How to create login logout system using php

login.php

      <html>
<head>
</head>

<body>
<form action="login_pro.php" method="post">
      username<br />
     <input type="text" name="unm">
     <br />
     <br />
     password<br />
     <input type="password" name="pwd">
     <br />
     <br />
     <input type="submit" value="login">
                      </form>
</body>
      </html>


login_pro.php

<?php session_start();
if (empty($_REQUEST['unm']) || empty($_REQUEST['pwd']))
{
echo "pleace enter username and password";
}
else
{
$link=mysql_connect("localhost","root","");
mysql_select_db("login",$link);
$unm=$_REQUEST['unm'];
$pwd=$_REQUEST['pwd'];

$q="select * from registration where unm='$unm' and pwd='$pwd'";

$res=mysql_query($q,$link)or die($row);
$row=mysql_fetch_array($res);

if(empty($row))
{
echo"wrong username or password";
}
else
{
$_SESSION['unm']=$row['unm'];
$_SESSION['status']=true;
header("location:index1.php");
}
}
?>

index1.php

<?php session_start();
if(isset($_SESSION['status']))
{
echo 'hello:'.$_SESSION['unm'];
echo '<a href="logout.php">Logout</a>';
}
else
{
header("location:logout.php");
}
?>

logout.php

<?php session_start();
 session_destroy();

header("location:login.php");
?>

How to insert,delete and select data from database using php

insert.php

<html>
<body>
<form action="insert_pro.php" method="post">
Name :<br />
<input type="text" name="nm" />
<br /><br />

Salary :<br />
<input type="text" name="sal" />
<br /><br />

<input type="submit" value="Insert">
</form>
</body>
</html>

insert_pro.php

<?php
$nm=$_POST['nm'];
$sal=$_POST['sal'];

$link=mysql_connect("localhost","root","") or die("can't connect");

mysql_select_db("employee",$link) or die("Wrong Database");

$q="insert into emp
(nm,salary)
values('$nm',$sal)";

mysql_query($q,$link) or die($q);

header("location:view.php");
?>

view.php

<html>
<body>
<table border="1" width="50%" align="center">
<tr>
<th>No</th>
<th>Name</th>
<th>Salary</th>
<th>Delete</th>
</tr>

<?php

$link=mysql_connect("localhost","root","");

mysql_select_db("employee",$link);

$q="select * from emp";

$res=mysql_query($q,$link);

while($row=mysql_fetch_array($res))
{
echo '<tr align="center">';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['nm'].'</td>';
echo '<td>'.$row['salary'].'</td>';
echo '<td><a href="delete_pro.php?no='.$row['id'].'">X</a></td>';
echo '</tr>';
}
?>
</table>
</body>
</html>

delete_pro.php

<?php
$id=$_GET['no'];

$link=mysql_connect("localhost","root","");

mysql_select_db("employee",$link);

$q="delete from emp where id=$id";

mysql_query($q,$link);

header("location:view.php");
?>

How to play video using html tag

video.html

<html>
<head>
</head>
<body>
<video controls>
<source src="aadat.mkv" type="video/mp4" height="500" width="500">
</video>

<video controls>
<source src="Axwell_-_Feel_the_Vibe[MINS00000880].mkv" type="video/mp4" >
</video>

<video controls>
<source src="Billo Rani.mkv" type="video/mp4" >
</video>
</body>
</html>

How to play song using html tag

song.html


<html>
<body>

<audio controls>
<source src="1.mp3" type="audio/mpeg" name="1">
</audio>
<hr size="10px" color="green"/>
<audio controls>
<source src="01.mp3" type="audio/mpeg" name="2">
</audio>

</body>
</html>

how to only image upload in database using php

form.php

<html>
<body>
<form action="form_pro.php"method="post"enctype="multipart/form-data">
<h1>Image:</h1>
<input type="file"name="img"/>
<br/><br/>
<input type="submit"value="upload"/>
</form>
</body>
</html>

form_pro.php

<?php
if(empty($_FILES['img']['name']))
{
echo "Please select image";
}
else
{
$ext=strtolower(substr($_FILES['img']['name'],-4));
if(!($ext==".jpg" || $ext=="jpeg" || $ext==".png" || $ext==".gif"))
{
echo "Wrong File";
}
else

{
$fname=time().$_FILES['img']['name'];
$fname=str_replace(" ","_",$fname);
move_uploaded_file($_FILES['img']['tmp_name'],"cbr/".$_FILES['img']['name']);
{
echo "Image Selected";
}
}
}
?>

captcha code with background image

captcha.php


<?php
$a="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str="";

for($i=1;$i<=6;$i++)
{
       $str=$str.substr($a,rand(0,strlen($a)-1),1);
}

$img=imagecreate(200,100);
imagecolorallocate($img,200,100,100);
imagettftext($img,20,0,20,70,8,"RAVIE.TTF",$str);
header("content-type:image/jpeg");
imagejpeg($img);
?>

How to upload image and image name in database using php

form.php

<?php session_start(); ?>

<form action="form_pro.php" method="post" enctype="multipart/form-data" style="font-size:10px;">
                                <?php 
                                    if (isset($_SESSION['o_e']['iname'])) 
                                    {
                                        echo '<span class="alert alert-danger">'.$_SESSION['o_e']['iname'].'</span>';
                                    } 
                                    if (isset($_SESSION['o_e']['req']))
                                    {
                                        echo '<span class="alert alert-danger">'.$_SESSION['o_e']['req'].'</span>';
                                    }
                                    if (isset($_SESSION['o_e']['wro']))
                                    {
                                        echo '<span class="alert alert-danger">'.$_SESSION['o_e']['wro'].'</span>';
                                    }
                                    if (isset($_SESSION['o_e']['up']))
                                    {
                                        echo '<span class="alert alert-success">'.$_SESSION['o_e']['up'].'</span>';
                                    }
                                    unset($_SESSION['o_e']);
                                ?>
                                <input type="file" name="o_img" class="form-control">
                                <br/>
                                <input type="text" name="i_nm" class="form-control" placeholder="Enter Image Name"/>
                                <br/>
                            
                                <input type="submit" value="    Upload    " class="btn btn-success">
</form>



form_pro.php


<?php  session_start();

$_SESSION['o_e']=array();
extract($_POST);
if (empty($_POST['i_nm']))
{
$_SESSION['o_e']['iname']="Enter Image Name";
header('location:form_pro.php');
}

if (!empty($_SESSION['o_e']))
{
header('location:form_pro.php');
}
else
{
if (empty($_FILES['o_img']['name']))
{
$_SESSION['o_e']['req']="First Fill all Details";
header('location:form_pro.php');
}
else
{
$ext=strtolower(substr($_FILES['o_img']['name'],-4));
if(!($ext==".jpg" || $ext==".jpe" || $ext=="jpeg" || $ext==".png" || $ext==".bmp" || $ext==".gif"))
{
$_SESSION['o_e']['wro']="Wrong File Selected";
header('location:form_pro.php');
}
else
{
$iname=time().$_FILES['o_img']['name'];
$iname=str_replace(" ","_", $iname);
move_uploaded_file($_FILES['o_img']['tmp_name'],"image/gallary/".$iname);


extract($_POST);

$link=mysql_connect('localhost','root','');

mysql_select_db('song_admin',$link);

$query="insert into header_image 
(iname,i_nm) 
values 
('$iname','$i_nm')";

mysql_query($query,$link);

$_SESSION['o_e']['up']="Image is Uploading";

header('location:form_pro.php');
}
}
}

?>

Featured post

what is ajax?how to create ajax with php code

Ajax Introduction -  એજેક્સ નો ઉપીયોગ કરી ને તમે પેજ લોડ કાર્ય વિના બધી માહિતી મેળવી શકો.એજેક્સ થી તમે કોઈ પણ ડેટા ઝડપ થી મેળવી શકો છો...