Showing posts with label web development. Show all posts
Showing posts with label web development. Show all posts

Thursday, January 5, 2023

Upload file from URL to Server using cURL in PHP


This Post show how to upload data or audio files on server getting from URL and how to download that file in PC using URL.


First put URL in string like below:

$url = 'http://s.cdnpk.eu/pk-mp3/love-dose/s165352040.mp3';

To Download file in PC its a simple short-cut.using download attribute of <a> tag in HTML.

echo "<a href='".$url."' download='myfile.wav'>Download</a>";


Now convert that URL to file using curl.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);

Now create a file on server. And open it in write mode.


  $fileName = "myfile.wav";
  $fh = fopen($fileName, 'w') or die("can't open file");


Write the file which we fetch from URL in 'myfile'. it was in $data variable.

  fwrite($fh, $data);
  fclose($fh);

Close the file that's it. Happy coding. :)


Saturday, December 31, 2022

How to search and find data from SQL database using PHP

In last post we learn how to delete data from sql database in this post i will show you how to find some data and verify that data from sql database using php.

So for this SQL select query is used and we select this time a user name and password to verify them. If the user name match with the name in database then this show an output that user verified.



<?php
include "conn.php";

$user = $_POST['user'];
$pass = $_POST['password'];


$sql = "select user,password from alogin where user='".$user."' and password='".$pass."';";
$result=$conn->query($sql);


if ($result->num_rows > 0) {
    echo "User Athenticate successfully";

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>


Create-connection-with-sql-database-in-php

Thursday, December 29, 2022

Cookies in PHP

To create cookies setcookie( ) method is used:


Example:
setcookie("name","usman" ,time( ) + (86400 * 30), "/");
Syntax:
setcookie(name, value, validity time, path, domain);

To retrieve value from cookies:

Example:
echo $_COOKIE['name'];
Syntax:
$_COOKIE['cookie name'];


To discard cookies:

set cookies expiry time 1 hour back
setcookie("name","usman" ,time( ) - (3600), "/");


Download Code


index.php


<form action="#" method="POST" class="myform">
<input type="text" name="user" placeholder="Enter Your Name..." />
<input type="submit" />
</form>

<div class="myinfo">
<?php 
if(isset($_COOKIE['uid'])){
echo "<h1>Your Name is : ".$_COOKIE['uid']."</h1>";
}
?>

</div>


new.php


<?php
if(isset($_POST['user'])){
$user = $_POST['user'];
setcookie("uid",$user,time() + (86400 * 30), "/");
header("location:index.php");
}

Friday, December 23, 2022

Add or Remove Input fields Dynamically Using JQuery - HTML

Add or Remove Input fields Dynamically Using JQuery - HTML
add/remove multiple input fields in html forms


if you are looking to add and remove duplicate input fields, here’s another jQuery example below to do the task for you. This jQuery snippet adds duplicate input fields dynamically and stops when it reaches maximum.

Code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID
    
    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="file" name="mytext[]"/><a href="#" class="remove_field">X</a></div>'); //add input box
        }
    });
    
    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});
</script>



<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="file" name="mytext[]"></div>

</div>




Tuesday, December 13, 2022

How to Create and Destroy sessions in PHP

Sessions are used in php for saving data which is used on several pages like in cpanel we need admin id on all pages to verify him and if the session destroy the user have to login again .
in this post i use a text box and two pages text box is to enter any value and then save that value in session and check on both pages that is this session exist? and if we destroy that session the value will not shown any more.


Start session:       session_start();
Assign value to session: $_SESSION['myname']= " $username";
Destroy session: session_unset();

Download Code


First page : index.php:


<!DOCTYPE html>
<html>
<head>
<title>Session is PHP</title>
</head>
<body>

<h2>To demonstrate the concept of session put a name in text box and check the session value by clicking buttons.</h2>
<h2><a href="usman.php">Second Page</a></h2>

<form action=" " method="POST">
<p><input type="text" name="username" placeholder="Type any name here..." required></p>
<p><input type="Submit" value="Check Session value"></p>
</form>

<form action=" " method="POST">
<p><input type="Submit" value="Distroy Session" name="dstroy"></p>
</form>
<?php
session_start();

if(isset($_POST['username'])){

$_SESSION['myname']=$_POST['username'];
echo "<br><h1>Session has a value= ".$_SESSION['myname']."</h1>";
}

if(isset($_SESSION['myname'])){
if(!isset($_POST['username']))
echo "<br><h1>Session has a value= ".$_SESSION['myname']."</h1>";
}

if(!isset($_SESSION['myname'])){
echo "<br><h1>Session not set...yet.!!</h1>";
}

if(isset($_POST['dstroy'])){
session_unset();
header("location:index1.php");
}

?>

<p>Check Session is user when user login in </p>
<p>Distroy session is used when user logout</p>
</body>

</html>



Second page: usman.php


<?php

session_start();
if(isset($_SESSION['myname'])){
 echo "<br><h1>Session has a value= ".$_SESSION['myname']."</h1>";
}

else{
echo "<br><h1>Session not set...yet.!!</h1>";
}


?>

<h2><a href="index1.php">First Page</a></h2>
<p>Check Session is user when user login in </p>

<p>Distroy session is used when user logout</p>


Saturday, December 10, 2022

Up-Date data in SQL database using Php

In last two posts i discus how to create connection and how to insert data in data base using php.

Insert-data-in-SQL-database-using-PHP


Create-connection-with-sql-database-in-php

In this post i will show you how to update data in SQL database table using php.
so for this first we need database connection which we create in first post so just include that file and then code for update query


Thursday, December 8, 2022

Insert Data in sql database using php

How to insert data in sql database using PHP?
In my previews post i show how to create connection with database using php and now in this post i show how to add data in database using php.

so for this first we need a table in database say login which have two columns user and password and we try to insert data in them so we use html form to get data from user and by using post method we get that data in php and then insert it in sql using sql query.


<?php
include "conn.php";

$a=$_POST['name'];
$b=$_POST['password'];

$sql = "INSERT INTO login (usar,pasword)
VALUES ('".$a."','".$b."'');";



if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>


we include the conn.php file here because we create connection in this file to learn how to create connection see create-connection-with-sql-database-in.html

Saturday, December 3, 2022

Thursday, December 1, 2022

Simple Portfolio example for web sites using HTML and CSS



Usman Siddique

Programming SeekerzzZ

Taxila,Cantt
PcpHunt

Experience

Have three year of experinece

Areas of Experience

PHP, HTML, C#, ASP>Net, C++, JS

Code here :

<html>
<style>
.behind h3{text-align: center;margin: 10px;}
.img1{height: 40%;width:40%;border-radius:100%;margin-left:27%;margin-top:10%;box-shadow:5px 3px 145px blue;}
.front h3,p{text-align:center;padding: 10px;}
h3,p{padding:0px;margin:0px;}
.main{margin:auto;width:20%;box-shadow: 2px 2px 25px green;}
.behind,.front{width: 100%;height: 40%;}
.behind{display: none;border: 2px solid skyblue;background-color: lightblue;}
.main:hover .front{display: none;}
.main:hover .behind{display: block;}

</style>
<div class="main">
<div class="front"> <img class="img1" src="b.jpg"><br><h3>Usman Siddique</h3><p>Programming SeekerzzZ</p><br><img src="as.jpg" >Taxila,Cantt<br><img src="as.jpg">PcpHunt</div>



<div class="behind"><h3>Experience</h3>Have three year of experinece<h3>Areas of Experience</h3>PHP, HTML, C#, ASP>Net, C++, JS</div>

</div>

Monday, November 28, 2022

Simple Count Down using Java-script - - HTML,CSS

Simple counter in java script 

Time Counter


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

HTML Code:



<div class="counter">
<h4>Time Counter</h4>

<p id="demo"></p></div>



JavaScript Code:




<script type="text/javascript">
var dely=15;
var i = 0, howManyTimes = 16;
function f() {
if(dely>9){document.getElementById("demo").innerHTML=("00:"+dely--);}
else{document.getElementById("demo").innerHTML=("00:0"+dely--);}
i++;
    if( i < howManyTimes ){
        setTimeout( f, 1000 );
    }else{}
}
f();

</script>



CSS Code:

Thursday, November 10, 2022

How to delete data in C# from sql database : code in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Data;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

 
        protected void Button2_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=localhost\SQLExpress;Initial Catalog=awais;Integrated Security=True;Integrated Security=True ");
            cnn.Open();
            string query = "delete from logout where name = '" +TextBox1.Text+ "';";
            SqlCommand cmd = new SqlCommand(query, cnn);
            cmd.ExecuteNonQuery();

            Response.Write("Deletion  is done!");

        }
    }
}

Monday, November 7, 2022

Pop-up Login Form using Java-Script and CSS.

Simple Pop-up Login Form On Mouse Over using Java-Script CSS and HTML. Programming Seekerz :)

Download Full Code From This Link



HTML:
<div class="btn" onmouseover="fun()">

<h1> Take Mouse Over Me And the Pop-Up Appers</h1></div>

<div class="pic" id="pic1">
<input type="button" onclick="yoyo()" value="X" class="cn"/>

<form class="myform" action="abc.html" method="post">
<input type="text" class="items" placeholder="User Name"/>
<input type="Password" class="items" placeholder="Password"/>
<input type="submit" class="btn1" value="LOG-IN"/>
</form>


</div>

CSS:

<style>
.cn{color:red;background-color:white;border:2px solid;border-radius:50px;float:right;}

.btn{color: red;font-size: 22px;border:1px solid;text-align:center;}

.pic{width: 25%;height: 27%;display:none;bottom:40%;right:40%;position:fixed;
box-shadow: 3px -3px 59px 42px rgba(46,54,43,0.40);
}

.myform{
  margin: auto;
  padding: 0px;
  height: 100%;
  width: 100%;
  background: hotpink;
  }
.items{
  border: 5px solid;
  border-radius: 10px;
  font-size: 18px;
  width: 80%;
  padding: 10px;
  margin: 10px;
}
.btn1{
  background: skyblue;
  border: 5px solid black;
  border-radius: 20px;
  padding: 10px;
  float:right;
  margin: 2%;
  color: black;
  font-size:14px;
  font-weight: bold;
  }


</style>


Sunday, November 6, 2022

Divide Content on multiple pages in PHP : Paging in PHP

Some time we have a lot of data like 600000 records and we want to show them but not all at a time so we use paging to divide them on separate pages in this post i will define how to use paging in PHP.
First we have to create a Database.


Database Name:Paging

Table:


CREATE TABLE `record` (
 
`Id` int(9) NOT NULL,

`Name` varchar(100) NOT NULL,

`Mobno` int(18) NOT NULL,

`Address` varchar(100) NOT NULL

) ;

And We put Dummy data on 100 records in it .
Now Retrieve that data.i use limit property in my query like
SELECT id,name,mobno,address from record limit 0,6

it will limit data in only 6 rows.
Now by using String Query's i create a hyper links containing page no and then on page load get them and use in limit value .


Formula: ( page_no - 1 ) * 6


Query String: <a href='usman.php?page=".$s1."'>".$s1."</a>"


Get Request:if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 


Total Records:
$sql1 = "SELECT COUNT(id) FROM record"; 
$result1 = $conn->query($sql1); 
$getresult = $result1->fetch_assoc(); 
$total = $getresult["COUNT(id)"];
$s=$total/6;



CSS Code For Style:

<style>
  span{padding:10px;margin:10px;
  bottom: 5%;position: fixed;}
  span a{margin: 20px;border: 1px solid green;padding: 10px;}
body{background-color: #eae;}
div{margin:5px auto;width: 50%;border: 5px solid;
background-color: skyblue; padding: 10px;}
div table{margin: auto;}
div table td{border: 5px solid green;}
</style>


PHP Full Code:

<?php
include "conn.php";
echo '<h1 style="text-align:center;">Pagging in PHP</h1>';
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$first = ($page-1) * 6;

$sql = "SELECT id,name,mobno,address from record limit $first,6" ;

$result = $conn->query($sql);

if ($result->num_rows > 0) {
while($row = $result->fetch_assoc())
 { 
echo "<div><table border=\"1\">";
echo    "<tr><th colspan=\"2\"width=200> Dummay Data For ".$row["id"]. "</th>";
echo    "<th rowspan=\"2\">";
echo    " Mobile No : ".$row["mobno"]."</th></tr>";
echo " <td>My Name: "  .$row["name"]. "</td>";
echo " <td>Yes My Name "  .$row["address"]. "</td></table></div>";
}} 

$sql1 = "SELECT COUNT(id) FROM record"; 
$result1 = $conn->query($sql1); 
$getresult = $result1->fetch_assoc(); 
$total = $getresult["COUNT(id)"];
$s=$total/6;
?>
<span>
<?php
for($s1=1;$s1<=$s;$s1++){
echo "<a href='usman.php?page=".$s1."'>".$s1."</a>";
}?>
</span>
<?php
$conn->close();
?>
 

Saturday, November 5, 2022

Ajax-Call : Password verification using ajax

Password verification using JavaScript-Ajax and HTML PHP.
To use this you have to include jQuery or use some jquery CDN and then create two file one for html code and other is for php and add the following code in and run on local host any one like xamp, wamp or some online server

Download Code

First for this we need an HTML file: say index.html

 paste following code in it:



<div>
<h1>The real password is admin</h1>

<input name="pass" type="password" id="pass"  placeholder="Enter any password">

<input type="button"  value="Check" onclick="check()">

</div>


Then the Java-Script code for this including Ajax is:



<script type="text/javascript">

function check(){
  var data = 'password='+document.getElementById('pass').value;
   obj={
    type:'post',
    data:data,
    url:'pass.php',
    success:function(msg){ alert(msg);      }
    };
   jQuery.ajax(obj);
 
 }
</script>


And the PHP code is. the php file name is pass.php:



<?php
extract($_REQUEST);

if($password==="admin"){
  
 echo "password matched";
  
}else{
 echo "password not matched";
  
}

?>

Friday, November 4, 2022

Thursday, November 3, 2022

Stylish Search bar example using jQuery

Stylish Search bar example using jQuery html and CSS it use jQueary online CDN for including jquery and use simple hide and show functions.

Download Code

Test here:




HTML Code:


<div class="main">
<img src="logo.png" id="display" />
<div class="search_bar" id="search">
<div class="box"><input type="text" placeholder="Search..." ></div>
<div class="btn"><input type="image" src="logo.png" alt="submit"></div>
</div>
</div>


JQuery Code:


<script>
$(document).ready(function(){
$("#display").click(function(){
$(this).hide();
$("#search").show();
});
$("#search").click(function(){
$(this).hide();
$("#display").show();
});
});
</script>


CSS code:


<style>
body{background-color:#eee;}
#display{height: 50px;width: 50px;border: 1px solid blue;border-radius: 10px;box-shadow: 2px 2px 10px skyblue;cursor:pointer;}
#search{padding: 10px;display: none;}
#search .box{float: left;}
#search input{height: 50px;box-shadow: 2px 2px 10px blue;}
#search input[type=image]{height: 42px;background-color: skyblue;border: 4px;border-style: solid;border-color: black;border-left: 0px;}
#search input[type=text]{padding: 12px;border: 4px;border-style: solid;border-color: black;border-right: 0px;}
.main{width:30%;margin:10% auto ;height:10%;box-shadow: 2px 2px 10px skyblue;padding:20px;background-color:#aaa;}
</style>

Wednesday, November 2, 2022

OnLine Doctor Appointment System Project in PHP - Programming seekerzZ

Read Also:  


OnLine Doctor Appointment System Project in PHP,HTML,CSS,Ajax


This is the complete PHP project on online doctor appointment system using PHP,HTML,Ajax,Javascript,CSS,Jquery and SQL .

To Download source code of Online Doctor Appointment System inbox me on Facebook.

Download From Here


https://www.facebook.com/usman.siddique.7771

OnLine Doctor Appointment System Project in PHP

Tuesday, November 1, 2022

Registration Form Using Div Elements in Html CSS

Read Also:  



CSS Code:

.heading{width: 30%;margin: auto;font-size:20px;font-family:arial;color:blue;}
input{padding: 1%;}
.main{border: 2px solid burlywood;width: 40%;margin: auto;padding: 2%;border-radius: 20px; }
.titles{float: left;width:50%;padding:3%;padding-left: 10%;font-size: 17px;}
.inputs{padding: 3%;}
.btn{margin: auto;width: 20%;padding: 3%;}
.botn{background-color: lightsteelblue;padding: 6%;border: 2px solid;border-radius: 10px;font-weight: bold;color: black;width:80%;}
body{background-color: #ddd;}


HTML Code:



<form action=" " method="get">

<div class="main">
<div class="heading">Registration Form</div>
<div class="titles"> First Name:  </div>
<div class="inputs"> <input type="text" >  </div>
<div class="titles"> Last Name:  </div>
<div class="inputs"> <input type="text" >  </div>
<div class="titles"> Father Name:  </div>
<div class="inputs"> <input type="text" >  </div>
<div class="titles"> Qualification:  </div>
<div class="inputs">  
           <select>
            <option>BSE</option><option>BSS</option><option>MSC</option>
            </select> 
       </div>
<div class="titles">  Gender: </div>
<div class="inputs"> 
<input type="radio" name="gnd" checked/>Male
<input type="radio" name="gnd"/>Female 
 </div>
<div class="titles"> Job Title:  </div>
<div class="inputs"> <input type="text" value="Android Develper" readonly/>  </div>
<div class="btn">  <input type="submit" value="Submit" class="botn"/> </div>
</div>

</form>

Monday, September 26, 2016

Upload file from URL to Server using cURL in PHP


This Post show how to upload data or audio files on server getting from URL and how to download that file in PC using URL.


First put URL in string like below:

$url = 'http://s.cdnpk.eu/pk-mp3/love-dose/s165352040.mp3';

To Download file in PC its a simple short-cut.using download attribute of <a> tag in HTML.

echo "<a href='".$url."' download='myfile.wav'>Download</a>";


Now convert that URL to file using curl.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);

Now create a file on server. And open it in write mode.


  $fileName = "myfile.wav";
  $fh = fopen($fileName, 'w') or die("can't open file");


Write the file which we fetch from URL in 'myfile'. it was in $data variable.

  fwrite($fh, $data);
  fclose($fh);

Close the file that's it. Happy coding. :)


Thursday, August 4, 2016