Thursday, January 30, 2014

Store File In DATABASE

Here I am going to tell you how can we send a file in database.
This is very general problem for a php developer
its is very basic PHP code you have to study and apply it.

1.upload_file.php
2.Add_file.php
3.List_file.php
4.Get_file.php

create database

username:root
password:
datbasename:test2
tablename:file

table entity:

CREATE TABLE `file` (

    `id`        Int Unsigned Not Null Auto_Increment,

    `name`      VarChar(255) Not Null Default 'Untitled.txt',

    `mime`      VarChar(50) Not Null Default 'text/plain',

    `size`      BigInt Unsigned Not Null Default 0,

    `data`      MediumBlob Not Null,

    `created`   DateTime Not Null,

    PRIMARY KEY (`id`)

)
<!DOCTYPE html>
<head>
    <title>MySQL file upload example</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
    <form action="add_file.php" method="post" enctype="multipart/form-data">
        <input type="file" name="uploaded_file"><br>
        <input type="submit" value="Upload file">
    </form>
    <p>
        <a href="list_files.php">See all files</a>
    </p>
</body>
</html>  


1.upload_file.php
 
<!DOCTYPE html>
<head>
    <title>MySQL file upload example</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
    <form action="add_file.php" method="post" enctype="multipart/form-data">
        <input type="file" name="uploaded_file"><br>
        <input type="submit" value="Upload file">
    </form>
    <p>
        <a href="list_files.php">See all files</a>
    </p>
</body>
</html>



<?php

// Check if a file has been uploaded

if(isset($_FILES['uploaded_file'])) {

    // Make sure the file was sent without errors

    if($_FILES['uploaded_file']['error'] == 0) {

        // Connect to the database

        $dbLink = new mysqli('127.0.0.1', 'user', 'pwd', 'myTable');

        if(mysqli_connect_errno()) {

            die("MySQL connection failed: ". mysqli_connect_error());

        }

        // Gather all required data

        $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);

        $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);

        $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']));

        $size = intval($_FILES['uploaded_file']['size']);

        // Create the SQL query

        $query = "

            INSERT INTO `file` (

                `name`, `mime`, `size`, `data`, `created`

            )

            VALUES (

                '{$name}', '{$mime}', {$size}, '{$data}', NOW()

            )";

        // Execute the query

        $result = $dbLink->query($query);

        // Check if it was successfull

        if($result) {

            echo 'Success! Your file was successfully added!';

        }

        else {

            echo 'Error! Failed to insert the file'

               . "<pre>{$dbLink->error}</pre>";

        }

    }

    else {

        echo 'An error accured while the file was being uploaded. '

           . 'Error code: '. intval($_FILES['uploaded_file']['error']);

    }

    // Close the mysql connection

    $dbLink->close();

}

else {

    echo 'Error! A file was not sent!';

}

// Echo a link back to the main page

echo '<p>Click <a href="index.html">here</a> to go back</p>';

?>

4.Get_file.php

<?php

// Connect to the database

$dbLink = new mysqli('127.0.0.1', 'user', 'pwd', 'myTable');

if(mysqli_connect_errno()) {

    die("MySQL connection failed: ". mysqli_connect_error());

}

// Query for a list of all existing files

$sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';

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

// Check if it was successfull

if($result) {

    // Make sure there are some files in there

    if($result->num_rows == 0) {

        echo '<p>There are no files in the database</p>';

    }

    else {

        // Print the top of a table

        echo '<table width="100%">

                <tr>

                    <td><b>Name</b></td>

                    <td><b>Mime</b></td>

                    <td><b>Size (bytes)</b></td>

                    <td><b>Created</b></td>

                    <td><b>&nbsp;</b></td>

                </tr>';

        // Print each file

        while($row = $result->fetch_assoc()) {

            echo "

                <tr>

                    <td>{$row['name']}</td>

                    <td>{$row['mime']}</td>

                    <td>{$row['size']}</td>

                    <td>{$row['created']}</td>

                    <td><a href='get_file.php?id={$row['id']}'>Download</a></td>

                </tr>";

        }

        // Close table

        echo '</table>';

    }

    // Free the result

    $result->free();

}

else

{

    echo 'Error! SQL query failed:';

    echo "<pre>{$dbLink->error}</pre>";

}

// Close the mysql connection

$dbLink->close();

?>
Read more....

Monday, January 20, 2014

PHP with OOPS

here you have to construct two PHP files 

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

 index.php

<?php
include("connection.php");
$obj=new apoo;
if(isset($_POST['SUB']))
{
   
    $un=$_POST['uname'];
    $up=$_POST['upass'];
   
    $yyy=$obj->AddUss($un,$up);
    }
//header("location:registration.php");
    ?>

<html>
<body>
<form method="post" action="">
username
<input type="text" name="uname" />
password

<input type="text" name="upass" />

<input type="submit" name="SUB" />

</form>
</body>
</html>


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

connection.php


<?php

session_start();
class CLASSNAME
{
    var $connect;
    function __construct()
    {
        $this->connect=new MySQLi("localhost","root","","sun12k");
        echo "success";
    }
  
    function AddUss($un,$up)
    {
        $addU=$this->connect->prepare("insert into`nametable`(firstname,lastname)VALUES(?,?);");
        $addU->bind_param("ss",$un,$up);
        $addU->execute();
    echo "success2";
       
        //    header("location:home.php");       
        }
}
?>
Read more....

Friday, January 10, 2014

top Company

 

 

 TOP Compnies

 

 

 

 

 

Kuliza Technologies Pvt Ltd

Hosur Main Rd, Bommanahalli , Bangalore / Bengaluru- 560068
Phone No. :(080) 42674300
Kuliza is a software development company that has built web, mobile and social experiences for global clients

Summit IT Solutions Pvt Ltd

Plot No.3 & 3A, EOIZ Industrial Area Sy.No.85 and 86, Sadaramangala Village Krishnarajapuram Hobli, Whitefield , Bangalore / Bengaluru- 560066
Phone No. :(080) 33071911
Symphony SUMMIT a cost effective, ITIL V3 certified, single window solution that unifies key applications across service, availability, people, and project and asset management.

1to1help.net Pvt Ltd

2728, Adjacent to ADE Compound 80 Feet Road (CMH Road Junction) Indiranagar , Bangalore / Bengaluru- 560038
Phone No. :(080) 71000121
1to1helps unique Employee Assistance Programme, developed over decade of corporate counseling experience in India, offers a combination of services ideally suited to the Indian setting.

Prudent Insurance Brokers Pvt Ltd

3rd Flr. "Sai Shakti" 2207 HAL Stage III 80 Feet Road Kodihalli , Bangalore / Bengaluru- 560008
Phone No. :(080) 30242000
Passionate client advocates, custodians of our clients assets, brokers with integrity and capability - this is Prudent Insurance Brokers. We help you protect your business and control insurance costs.

ACTT Global

101 Sadashiv Apts 20,Langford Garden Rd , Richmond Circle , Bangalore / Bengaluru- 560025
Phone No. :(080) 22107376
ACTT Global is a performance improvement enterprise.

Greytip Software Pvt Ltd

30/31, 100 Feet Road, II Block Koramangala , Bangalore / Bengaluru- 560034
Phone No. :(080) 40225900
Greytip Software is a leading HR & Payroll software solutions company.
 

Peak Performance Trainings

4, 2nd Floor, 324/62, Sarvasheela Complex, Bellary Main Road, Ganganagar, , Bangalore / Bengaluru- 560032
Phone No. :(080) 41378973
Peak Performance Trainings is a training company Headquartered at Bangalore.
 

Clearnet Solutions India Pvt Ltd

19 1st Floor Umiya Emporium 99 Hosur Main Road - Dairy Circle Side Opposite Forum Mall , Bangalore / Bengaluru- 560029
Phone No. :(080) 9019177688
Clearnet Solutions India Private Limited is a networking company.

10kInfo Data Solutions Pvt Ltd


Industry :Information Technology (IT)
Sub Industry :IT- Consulting
Company Type :SMEs
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560027


12th Avenue


Industry :Hospitality
Sub Industry :Hotels
Company Type :SMEs
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560008


24/7 Customer Pvt Ltd


Industry :ITES - BPO , KPO , LPO , MT
Sub Industry :BPO , KPO , Call centre
Company Type :MNC
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560071



24x7 Learning Pvt Ltd


Industry :Institutes , Training
Sub Industry :Educational Consultants, Institutes - Others
Company Type :Industry Best
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560042


37th Crescent


Industry :Hospitality
Sub Industry :Hotels, Restaurants, Banquet Halls, Associations
Company Type :Industry Best
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560001


3AG Network Solutions Pvt Ltd


Industry :Information Technology (IT)
Sub Industry :IT- ERP , CRM
Company Type :SMEs
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560003


3C Consultants Pvt Ltd


Industry :Consulting
Sub Industry :Placement , HR , Training
Company Type :SMEs
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560017


3D Concept Analysis & Development India Pvt Ltd


Industry :Information Technology (IT)
Sub Industry :IT Software , QA -Testing
Company Type :SMEs
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560040


3D Concept Tooling Pvt Ltd


Industry :Engineering
Sub Industry :Machineries , Instruments
Company Type :SMEs
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560058


3D Solid Compression Pvt Ltd


Industry :Information Technology (IT)
Sub Industry :IT Software , QA -Testing
Company Type :SMEs
Level of Office :Head Office
Location :    Bangalore / Bengaluru / Karnataka - 560003








Read more....

Wednesday, January 8, 2014

PHP Mail with attachment file

Here i am discuss very important problem faced by many programer and web developer  
mail with attachment   
here you can solve this problem

1.create  checkMail.php
save it checkMail.php in server folder .

code

 checkMail.php

<?php
    if(isset($_POST['submit']))
    {
        //The form has been submitted, prep a nice thank you message
        $output = '<h1>Thanks for your file and message!</h1>';
        //Set the form flag to no display (cheap way!)
        $flags = 'style="display:none;"';

        //Deal with the email
        $to = 'himmat.singh@gmail.co';
        $subject = 'Message';
                $name = $_POST['name'];
                $email_address = $_POST['email'];
                $message = $_POST['message'];

         $message = "\n\n Name: $name \n\n Email: $email_address \n\nMessage: \n\n $message \n\nHere is your file: ";
       
   

        $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
        $filename = $_FILES['file']['name'];

        $boundary =md5(date('r', time()));

        $headers = "From:admin@example.com\r\nReply-To: admin@php999.com";
        $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

        $message="This is a multi-part message in MIME format.
     
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$message

--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

$attachment
--_1_$boundary--";

        mail($to, $subject, $message, $headers);
    }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>MailFile</title>
</head>

<body>

<?php echo $output; ?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" <?php echo $flags;?>>
<p>
<label for="message">Message</label>

 <textarea name="message" id="message" cols="20" rows="8"></textarea></p>
<p>
<label for="name">Name</label>  

<input type="text" name="name" id="name" ></p>
<p>
<label for="name">Name</label>  

<input type="text" name="email" id="name" ></p>
<p>
<label for="name">Name</label> <input type="text" name="contact" id="name" ></p>
<p>
<label for="file">File</label> <input type="file" name="file" id="file"></p>
<p>
<input type="submit" name="submit" id="submit" value="send"></p>
</form>
</body>
</html>

Hi! Thank you everyone who reading my article. My major is electronic and programming. Right now I am doing foreign study at India. I will like sharing to everyone with my works and if you do interesting with my works, please leave you comment on my blog. Any comments is welcoming.
Read more....

Friday, January 3, 2014

Insert into Data Base Using PHP

Here i am going to tell you how to insert data into database and how can we connect a php page to the database 
the connection is made in php page by using the query in html page.



<html>
<body>
<h1>A small example page to insert some data in to the MySQL database using PHP</h1>
<form action="insert2.php" method="post">
Firstname: <input type="text" name="fname" /><br><br>
Lastname: <input type="text" name="lname" /><br><br>
<input type="submit" />
</form>
</body>
</html>

insert.php
 
<html><body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sun12k", $con);
$sql="INSERT INTO nametable (firstname, lastname)
VALUES
('$_POST[fname]','$_POST[lname]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
mysql_close($con)
?>
</body>
</html>
Read more....

PDF generation in PHP

here i am going to tell you how can we generate a PDF page using PHP
use 3 easy steps.

You are able to take print out of your data

1. first download FPDF from official site of php.

http://www.fpdf.org/en/dl.php?v=17&f=zip
 
2.put it into web Server folder.

3.connect it with php file using require. 


create-pdf.php




Read more....

Error in PHP page

<?php
session_start();
class add
{
    var $conn;
   
    function __construct()
    {
        $this->conn=new MySQLi("localhost","root","","bis_tally");
    }
   
   
   
   
    //-----------------------------------
    function addStudent($user_name,$user_pass,$user_email,$user_contact)
    {
        $addUser=$this->conn->prepare("INSERT INTO                           `user`(user_name,user_pass,user_email,user_contact)VALUES(?,?,?,?);");
        $addUser->bind_param("ssss",$user_name,$user_pass,$user_email,$user_contact);
        $addUser->execute();
        //--------------error
    header("location:index.php");   
    echo "you are registred"    ;
    //-----------------
    }
   
    function addBuyer($company_address,
                        $buyer_name,
                        $invoice_number,
                        $date,$delivery_note,
                        $terms_of_payment,
                        $supplier_reference,
                        $other_reference,
                        $buyer_order_number,
                        $date_1,
                        $despatch_doc_number,
                        $date_2,
                        $despatched_through,
                        $destination,
                        $terms_of_delivery,   
                        $particular,
                        $quantity,
                        $rate,
                        $percentile,
                        $amount,
                        $service_tax)
    {
       
        $addInfo=$this->conn->prepare("INSERT INTO `buyer`(company_address,buyer_name,invoice_number,
        date,delivery_note,terms_of_payment,supplier_reference,other_reference,buyer_order_number,date_1,despatch_doc_number,date_2,
        despatched_through,destination,terms_of_delivery,particular,quantity,rate,percentile,amount,service_tax)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);");
       
        $addInfo->bind_param("ssisssssssssssssiiiis",$company_address,$buyer_name,$invoice_number,
        $date,$delivery_note,$terms_of_payment,$supplier_reference,$other_reference,$buyer_order_number,
        $date_1,$despatch_doc_number,$date_2,$despatched_through,$destination,$terms_of_delivery,$particular,$quantity,
        $rate,$percentile,$amount,$service_tax);
        $addInfo->execute();
       
    }//-------------------------new function for amount  --------------------
        function addAmount($invoice_number,$quantity,$rate,$percentile,$amount)
        {
        $addValue=$this->conn->prepare("INSERT INTO `amount2`(invoice_number,quantity,rate,percentile,amount) VALUES (?,?,?,?,?);");
        $addValue->bind_param("iiiii",$invoice_number,$quantity,$rate,$percentile,$amount);
        $addValue->execute();
        }
        //--------------------------------------------------------------------
   

    function login($user_name,$user_pass)
      {
          $login=$this->conn->prepare("SELECT * FROM `user` WHERE `user_name`='".$user_name."' AND `user_pass`='".$user_pass."'");
          $login->bind_param("ss",$user_name,$user_pass);
          $login->execute();
          $login->store_result();
          if($login->num_rows == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
      }
    // next function..... contd...
   
 }
?>



very important concept of SSSSS.....
contd....
Read more....
Related Posts Plugin for WordPress, Blogger...