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!


    NEW! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    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! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository.
    FREE! Go There Now!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Hacking 101

    Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today.
    FREE! Go There Now!


    NEW! Integrating XML into Your Enterprise Using Data Federation

    XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats.
    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!



    All FREE IBM® developerWorks Tools!

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - 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





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