PHPBuilder - PHP, MySQL and images Page 4



RSS Twitter
Articles Tricks And Hacks

PHP, MySQL and images - Page 4

by: William Samplonius
|
July 30, 2000

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.

« Previous Page
1
|
2
|
3
|
4

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
William Samplonius

Comment:



Comment:

(Maximum characters: 1200). You have characters left.