#native_company# #native_desc#

PHP, MySQL and images Page 4

By William Samplonius
on 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.


if ($submit) {

    $db mysql_connect("$localhost","$joesauto","$password");


    $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";

"make: $make<br>n";

"model: $model<br>n";

"price: $price<br>n";

"temp file: $picture<br>n";

"file name: $picture_name<br>n";

"file size: $picture_size<br>n";

"file type: $picture_type<br>n";


"<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.