Jago6060 Posted June 5, 2007 Share Posted June 5, 2007 I'm having some issues with the cooperation of PHP and MySQL. I'm trying to have a single script perform the upload fuction, access the database, and put a record into my images table. So far it'll just upload the image but I can't seem to get it to put anything into the database. any suggestions? this is my upload.php <? session_start(); include 'connect.php'; $sql = "insert into crc_images (img_id,img_dir)values('1','$_POST[uploadedfile]')"; // Where the file is going to be placed $target_path = "./uploads/images/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; }else{ echo "There was an error uploading the file, please try again!"; } ?> Link to comment https://forums.phpfreaks.com/topic/54334-solved-tricky-file-upload/ Share on other sites More sharing options...
MikeDXUNL Posted June 5, 2007 Share Posted June 5, 2007 First off $sql = "insert into crc_images (img_id,img_dir)values('1','$_POST[uploadedfile]')"; you dont have to insert the id there. well as long as the "img_id" is set to auto_increment in your database. also, it would be $_FILES['uploadedfile'] not $_POST try something like this: // Check if file was uploaded if (!is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) { $error = "you didn't select a file to upload.<br />"; echo $error; } else { // Check if acceptable file extension $ext = strrchr($_FILES['uploadedfile']['name'], "."); if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG") { $error = "your file was an unacceptable type.<br />"; echo $error; unlink($_FILES['uploadedfile']['tmp_name']); // Upload and Replace photo } else { $newname = ENTER_NAME_HERE.$ext; move_uploaded_file($_FILES['uploadedfile']['tmp_name'],"YOUR_PATH/".$newname); mysql_query("INSERT into crc_images (img_dir) VALUES ('$newname')") or die (mysql_error()); find some kind of system for the $newname and change your_path to where all the files are uploaded too. if you need any extra help. PM me. Link to comment https://forums.phpfreaks.com/topic/54334-solved-tricky-file-upload/#findComment-268709 Share on other sites More sharing options...
micah1701 Posted June 5, 2007 Share Posted June 5, 2007 'um, where in your code are you actually sending your $sql query string to your database? under the line $sql = "insert into crc_images (img_id,img_dir)values('1','$_POST[uploadedfile]')"; you need to have something like : mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/54334-solved-tricky-file-upload/#findComment-268710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.