need help with upload image and getting image name to db
i'm using this upload code below.
i am a student working on an ecommerce project
i have an ecommerc website and an admin on the page that i have, i'm working on the admin part at the moment.
i want the admin to enter info into all of the fields that are provided such as the item name, item description, and item price, and item image.
here is the site that i'm working on for an example
i would like the name to be inserted into the datbase in order for the image to show up on the ecommerc website on the products pages here is my ecommerce site i have
can anyone help me out in getting the image name, which is being uploaded, to the database so that the image will show up on the products page of the ecommmerce website any help would be appreciated.
thanks
this is the code that i'm using for uploading the image and inserting the image into the database:
Something basic, but it works for me. Upload.php adds the info to a database, randomly renames the file, and uploads the file to a directory. Allows only jpg's, checks that all fields are filled in. Change"my_site/photos" to where the files will be stored. Checks for max file size and incorrect file type. Need to change your database connection values, the table name, and the page to redirect to.
$max_size = 1024000; $filesize = $_FILES['upfile']['size']; $filetype = $_FILES['upfile']['type']; $upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/my_site/photos/"; if((!$fname) || (!$title) || (!$desc)){ echo 'You did not submit the following required information. Use your browsers "back" button to complete your form. <br />'; if(!$fname){ echo "Name is a required field. <br />"; } if(!$title){ echo "Photo title is a required field. <br />";
} if(!$desc){ echo "Photo description is a required field. <br />";
$dbuser="your user name"; $dbpass="your password"; $database="database name"; $conn = mysql_connect(localhost,"$dbuser","$dbpass") or die ("Could not connect to MySQL"); mysql_select_db("$database") or die ("Could not open database"); $query = "INSERT INTO table_name VALUES('','$fname','$title','$desc','$filename')"; $result=mysql_query($query); } } mysql_close(); header ('Location: redirect page.ext'); }