Showing posts with label php. Show all posts
Showing posts with label php. 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");
}

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

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

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

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. :)


Sunday, April 24, 2016

Delete Data in SQL Database using PHP

In my last three posts i covers the topics that how to create connection insert data and then if we want to update that data so then how to update data in in sql database table using php.

For step by step learning see my privies posts on database and php.









Today in this post we delete a record from login table we take a form inputs from user where he gave us the name and password of the user which he want to delete.


<?php
include "conn.php";

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


$sql = "DELETE from login 
        where user='".$user."' and PASSWORD='".$pass."' ";

if ($conn->query($sql) === TRUE) {
    echo "Record Deleted successfully";

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

$conn->close();
?>




Wednesday, April 13, 2016

Create Connection with SQL Database in PHP

How to create connection with mysql database using PHP ?

So for this first create a database in myPhpAdmin and then use that name in mysqli default constructor by default the password was null and user name is root. If you are using XAMP then the servername is localhost.


<?php
$servername = "localhost";
$username = "root";
$password = Null;
$dbname = "paging";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else{
echo "Connection Sucssful";
}

?>


copy paste above code save in conn.php file and run on localhost like localhost/conn.php

Sunday, June 28, 2015

Calculator using PHP and Css 3 ,html 5

Calculator Using PHP...

<title>Calculator</title>
<style>
span{
background-color: lightgreen;
border: 2px solid black;
textcolor: red;
}
div input{
    background-color: lightgrey;
    width: 320px;
    padding: 5px;
    border: 1px solid navy;
    margin: 25px;
}
div button{
    background-color: #FFFFF0;
    width: 360px;
    height: 40px;
    padding: 5px;
    border: 2px solid green;
 
}
div td{
    background-color:#FFEBFF;
    width: 200px;
    height: 10px;
    padding: 5px;
    border: 2px solid navy;
    }
div th{
    background-color: #FFD6D6;
    width: 200px;
    height: 10px;
    padding: 5px;
    border: 2px solid navy;
 
}
 p{
    background-color: #FFF5FF;
    width: 420px;
    height: 25px;
    padding: 5px;
    border: 3px solid black;

}
</style>


<form action=" " method="POST">
<div><table border=2"><tr><th color="red" width="59">
Value 1:<br><input type="text" name="a" ></th><th>
Value 2:<br><input type="text" name="b" ></th></tr><tr><td>
<input type="radio" name="s" value="+">Additon<br></td><td>
<input type="radio" name="s" value="-">Subtraction<br></td></tr><tr><td>
<input type="radio" name="s" value="*">Multiplication<br></td><td>
<input type="radio" name="s" value="/">Division<br></td></tr><tr><td>
<input type="radio" name="s" value="sin">Sin<br></td><td>
<input type="radio" name="s" value="cos">Cos<br></td></tr><tr><td>
<input type="radio" name="s" value="tan">Tan<br></td><td>
<input type="radio" name="s" value="decbin">Decimal to Binary<br></td></tr><tr><td>
<input type="radio" name="s" value="bindec">Binary to Decimal<br></td><td>
<input type="radio" name="s" value="dechex">Decimal to Hexa<br></td></tr><tr><td>
<input type="radio" name="s" value="hexdec">Hexa to Decimal<br></td><td>

</div>
<button value="Submit" name="submit" type="Submit">Submit</button></td></tr>
</form>

<tr>
<?php
$ans=0;
$a=$_POST['a'];
$b=$_POST['b'];
$q=$_POST['s'];
switch($q)
{
case "+":
$ans=$a+$b;
echo "Sum= ".$ans;
break;
case "-":
$sub=$a-$b;
echo "Sub= ".$sub;
break;
case "*":
$mul=$a*$b;
echo "Mul= ".$mul;
break;
case "/":
$div=$a / $b;
echo "DIV= ".$div;
break;
case cos:
 $ans = cos($a);
  break;
  case sin:
 $ans = sin($a);
  break;
  case tan:
 $ans = tan($a);
  break;
  case decbin:
 $ans = decbin($a);
  break;
  case bindec:
 $ans = bindec($a);
  break;
  case dechex:
 $ans = dechex($a);
  break;
  case hexdec:
 $ans = hexdec($a);
  break;
  case deg2rad:
 $and = deg2rad($a);
  break;
  case rad2deg:
 $ans = rad2deg($a);
  break;
}
echo "<p><i><b> Answer =<b><i> ".$ans."</p>";
//echo "<input type=/"text/" value='".$ans."'>";


?></tr></table>

<center><span>Copyright @ Programming SeekerzzZ </span></center>




Value 1:
Value 2:
AdditonSubtraction
MultiplicationDivision
SinCos
TanDecimal to Binary
Binary to DecimalDecimal to Hexa
Hexa to Decimal
Answer = ".$ans.""; ?>
Copyright @ Programming SeekerzzZ

Saturday, June 27, 2015

Monday, January 12, 2015

Basic Syntax of PHP

PHP stands for PHP: Hypertext Preprocessor.


A PHP script can be placed anywhere in the document.

A PHP script starts with <?php and ends with ?>:

<?php
// PHP code goes here
?>

The default file extension for PHP files is ".php".

A PHP file normally contains HTML tags, and some PHP scripting code.