How to create shopping cart with file upload?

Asked By 40 points N/A Posted on -
qa-featured

Hello Techyv,

How to create a shopping cart with file upload?

Do you have some illustration or sample that can help me create my own shopping cart and allow the website administrator to upload an image for the product as well as to key in the product number and prices?

I need some help.

Expecting some help from you guys. 

Thank you.

SHARE
Best Answer by Luker Malcom
Best Answer
Best Answer
Answered By 5 points N/A #187199

How to create shopping cart with file upload?

qa-featured

Hello Trevor Jhon,

If you are planning to create a simple shopping cart and would like to use file upload, then I suggest that you use PHP code because it's easier to create and understand. Here is an example of a file upload code that you can refer to:

<form action='upload.php?' method='post' enctype="multipart/form-data">
            <table>
                <tr><td>Item ID:</td><td>Photo:</td><td>Item Name:</td><td>Price:</td><td>Quantity:</td></tr>
                <tr>
                    <td><input type="file" value="" name="file" ></td>
                    <td><input type="text" value="" name="itemname"/></td>
                    <td><input type="text" value="" name="itemprice"/></td>
                    <td><input type="text" value="" name="itemqty"/></td>
                </tr>
                <tr>
                    <td><input type=submit name=do value=submit /></td>
               </tr>
            </table>
        </form>

Here is what it will look like:

simple shopping cart

The code above simply shows the fields that you need to fill-up in order to put some items in your database (I suggest you use MySQL as your database). Each field is assigned to unique <input name> to make sure that they will be properly placed in the database as well as in PHP. The <form> part is the one responsible for calling the PHP page that gets the command for uploading the content of those fields into your database so later the page can display it. Here is the code that ‘upload.php’ contains:

<?php
           $db= new DB();
            $db->connect();

            if(isset($_POST['do']) && $_POST['do'] == "submit"){
               $image =$_FILES["file"]["name"];
          $db->insert('upload',array($image,$_POST[itemname],$_POST[itemprice],$_POST[itemqty]),

'Itemphoto,Itemname,Itemprice,Itemqty'); }
?>

In this code, mysql database is called and PHP connects with it. Below it, a condition should be met – if the user clicks on submit, the image uploaded will be placed in a temporary file name called 'image' and will then be stored in the database together with other string data such as the price, quantity, and item name. They will be respectively placed on database tables named as 'itemhpoto, itemname, item price, and itemqty'.

Hope this solution gave you an idea on how to start your own shopping cart.

Answered By 0 points N/A #187200

How to create shopping cart with file upload?

qa-featured

Trevor Jhon,

I think you've already got the script code for file upload from other comment's.

But I’m going to give the total shopping cart system scripts in my attachments.

If you've some basic skill in PHP & Java even then you can do this easily.

If you search on webs then you'll find many scripts for HTML but I refer you to use PHP or Java scripts.

Hope it will help you.

Related Questions