(Developer Shed Network) Server Side - PHP - User Contributed - PHP, MySQL, and Images
(Developer Shed Network) Server Side - PHP - User Contributed - PHP, MySQL, and Images
Table of Contents
PHP, MySQL, and Images.................................................................................................................................1
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.20alog 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.
Ok, after a lot of reading I 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), CHAR(20), > price CHAR(15), > picture_name CHAR(25), > );
> model
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
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="
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.
\n"; echo "make: $make \n"; echo "model: $model \n"; echo "price: $price \n"; echo "temp file: $picture \n"; echo "file name: $picture_name \n"; echo "file size: $picture_size \n"; echo "file type: $picture_type \n"; echo " n"; echo " \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
UserContributed: PHP, Mysql, and Images 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.