suhaib Posted October 20, 2021 Share Posted October 20, 2021 (edited) I need it to be uploaded to the database. Do you know how to fix it ? Because when I uploaded image show it error massageI need it to be uploaded to the database. Do you know how to fix it ? Because when I uploaded image show it error massage $title = $_POST['title']; $info = $_POST['info']; $text = $_POST['text']; // varabls Uploud $imgssName = $_FILES['img']['name']; $imgSize = $_FILES['img']['size']; $imgTmp = $_FILES['img']['tmp_name']; $imgType = $_FILES['img']['type']; // Chek extensions Img $file_parts = pathinfo($imgssName); $file_parts['extension']; $cool_extensions = Array('jpeg', 'jpg', 'JPG', 'png', 'PNG', 'gif', 'JPEG', 'GIF', 'pdf','psd'); if (in_array($file_parts['extension'], $cool_extensions)){ // Chek Size Img $img = rand(0, 100000000) . '_' . $imgssName; move_uploaded_file($imgTmp, "uploads/imgs//" . $img); $stmt = $con->prepare("INSERT INTO news(title,info,text,img,date) VALUES (:btitle, :binfo, :btext, :bimg, now() )"); $stmt->execute(array( 'btitle' => $title, 'binfo' => $info, 'btext' => $text, 'bimg' => $img, )); ? Edited October 21, 2021 by cyberRobot Moved question / description into the message body Quote Link to comment https://forums.phpfreaks.com/topic/314058-uploading-images-to-the-database/ Share on other sites More sharing options...
suhaib Posted October 20, 2021 Author Share Posted October 20, 2021 Warning: Undefined array key "img" in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 17 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 17 Warning: Undefined array key "img" in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 18 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 18 Warning: Undefined array key "img" in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 19 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 19 Warning: Undefined array key "img" in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 20 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 20 Warning: Undefined array key "extension" in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 26 Warning: Undefined array key "extension" in C:\xampp\htdocs\suhaib1\admin\insert-news.php on line 29 الصورة غير معرفه Quote Link to comment https://forums.phpfreaks.com/topic/314058-uploading-images-to-the-database/#findComment-1591251 Share on other sites More sharing options...
suhaib Posted October 20, 2021 Author Share Posted October 20, 2021 Quote Link to comment https://forums.phpfreaks.com/topic/314058-uploading-images-to-the-database/#findComment-1591252 Share on other sites More sharing options...
ginerjm Posted October 20, 2021 Share Posted October 20, 2021 If you have code to show us then show us the code - not a black image! I think you don't have 'img' as the name on your INPUT tag for the 'file' Quote Link to comment https://forums.phpfreaks.com/topic/314058-uploading-images-to-the-database/#findComment-1591253 Share on other sites More sharing options...
ginerjm Posted October 20, 2021 Share Posted October 20, 2021 Also - wouldn't it be better to add the random number after the real filename to make it easier to find the file by its original name? Quote Link to comment https://forums.phpfreaks.com/topic/314058-uploading-images-to-the-database/#findComment-1591254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.