PHP
  Home arrow PHP arrow User-Contributed: PHP, Mysql, and Imag...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

User-Contributed: PHP, Mysql, and Images
By: Dev Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    1999-08-03

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    by Willim Samplonius

    Joe's used auto sales, an average sized car yard of around 150 cars has decided to make the big leap into the new millennium. First of all they had to get themselves a nice new computer, with that new computer came the "Internet". After a few weeks of searching the internet they decided to go all out, now they wanted a web site of their own. And it just so happens that Joe's good friend knows a little HTML, three days later Joe's used auto sales was online and ready for business.

    It wasn't long before they realized they were not going to get very far with that site. They needed something where they could add, modify and delete listings in a database. Well, to make a long story short they ended up contacting me. And of course I said I could do it. So, that day I had to find out what type of database to use. After asking a few questions I decided to create a database using PHP and MySQL

    I didn't know how to create an actual MySQL database, so I contacted support at my hosting company, next thing I know I had a database called "joesauto" and a few basic Telnet and MySQL commands.

    Now I needed to open up telnet for the first time and enter my login name and password. Before I could go any further I had to learn a little about MySQL.

    OK, now that we all know the basics, its time to connect to the server. If you have any problems email support, they like answering these questions.


    shell> mysql -h localhost -u joesauto -p Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 459 to server version: 3.22.20a-log Type 'help' for help. mysql>

    After successfully connecting to the server we need to access the database (joesauto) that I got support to create for me. If you don't have a database yet now is the time to create one. To see what databases are on this server type show databases; if your database is there select it by typing use joesauto if you can't access the database contact support. This tutorial could take days if your support is slow.


    mysql> use joesauto Database changed mysql>

    Ok, after a lot of readingI figured out how to create a table for all the important data (year, make, model, price and picture), the picture part took alot of time to figure out, I found out that it was best to just store the picture filename in the database and store the actual picture in a specified directory on my server. Below is what I used to create the table. (I am sure there are other ways of creating this table but, this is what worked for me.)


    mysql> CREATE TABLE joesauto(    -> year INT(4),    -> make CHAR(20),    -> model CHAR(20),    -> price CHAR(15),    -> picture_name CHAR(25),    -> );

    At this stage we don't need to worry about loading data into the table, we will do that next using PHP and simple HTML forms. You can shut down Telnet now and open up your favorite HTML editor, I would recommend Homesite 4.0.

    Now it was time for me to learn the PHP basics, which wasn't that difficult, then I subscribed to the PHP mailing list and took a quick look through the PHP manual. If you can try to find somebody on ICQ that knows PHP, it sure does help having instant support.

    The idea here is to be able to insert all the data into the database via the internet using forms, I have created forms several times before so that was no problem at all. I am assuming that you have used forms before, if you have no idea how to create forms, find a tutorial on the net and come back when your ready.

    Create a page and call it add_data.php3, and then cut and paste the following.

    add_data.php3
    
    <form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF ?>"> year <input type="Text" name="year" size="25"> make <input type="Text" name="make" size="25"> model <input type="Text" name="model" size="25"> price <input type="Text" name="price" size="25"> picture <input type="File" name="picture" size="25"> <input type="submit" name="submit" value="Upload"> </form>
    First of all we need to add a little PHP in the action attribute, this is used to display all the data once the submit button is pressed.

    action="<?php echo $PHP_SELF ?>
    The name attribute within the input element will be used to pass the information to PHP, these names should be the same as the columns in the database.

    Now its time to add the stuff that makes it all work. I can't really explain what we are using below, so I suggest you go to the PHP website and study the main elements used below, mysql_connect() and mysql_select_db(). It may be a good idea to go to the MySQL site and learn how to insert, delete, modify and anything else you want to fill your brain with.

    <?php if ($submit) { $db = mysql_connect("$localhost","$joesauto","$password"); mysql_select_db("$joesauto",$db); $sql = "INSERT INTO joesauto (year,make,model,price,picture_name) VALUES ('$year,$make,$model,$price,$picture_name')"; exec("cp $picture /full/path/to/joesauto/images/$picture_name"); echo "year: $year<br>\n"; echo "make: $make<br>\n"; echo "model: $model<br>\n"; echo "price: $price<br>\n"; echo "temp file: $picture<br>\n"; echo "file name: $picture_name<br>\n"; echo "file size: $picture_size<br>\n"; echo "file type: $picture_type<br>\n"; echo "<br>n"; echo "<img src=images/$picture_name><br>\n"; } ?>
    After you add the above code to the add_data.php3 page, (right below the closing form tag would work great) you need to change a few things to work with your database. It should all be pretty straight forward, you just need to change $your_username, $your_password and you'll need to specify the full path to where your images directory is. You also need to make sure that the image directory is CHMOD 777.

    Now everything should be set and your ready to upload it to the server to see if everything works. The next lesson in this tutorial will show you how to view the data, and I will show you how to do more stuff in lessons to follow.

    My name is William Samplonius and I am web designer for e n d u r a d e z i n e. I hope this helped you, don't email me your questions because I know just as much as you do.

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More PHP Articles
    More By Dev Shed

     

    IBM® developerWorks developerWorks - FREE Tools!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Evaluate Rational Host Access Transformation Services (HATS) Toolkit V7.1

    Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    FREE! Go There Now!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! The dirty dozen: preventing common application-level hack attacks

    As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
    FREE! Go There Now!


    NEW! Trial download: IBM Lotus Forms V3.0

    Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Manual Tester V7.0.1

    Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Tester for SOA Quality V7.0.1

    Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services.
    FREE! Go There Now!


    NEW! Try IBM Rational Asset Manager V7.0 online!

    You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

       

    PHP ARTICLES

    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway