I created a database with 2 fields
Id INT(11) Primary Auto_Increment not null
photo Text Null
The code below successfully uploads the image to the directory however the image path doesn’t save to my database. Does anybody have any idea what im doing wrong. Sorry if it is something obvious im a php beginner and im new to uploading images with php. Thanks.
<?php $pic=($_FILES['photo']['name']); if((!empty($_FILES['photo'])) && ($_FILES['photo']['error'] == 0)) { $filename = basename($_FILES['photo']['name']); $ext =substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG" || $EXT == "gif" || $ext =="GIF" || $ext =="PNG" || $ext =="png") && ($_FILES['photo']['size'] <1000000)) { $newname = dirname(__FILE__).'/images/'.$filename; if (!file_exists($newname)) { if ((move_uploaded_file($_FILES['photo']['tmp_name'],$newname))) { echo "The file has been saved as: ".$newname; } else { echo "Error file not uploaded"; } }else { echo "Error: File ".$_FILES["photo"]["name"]." already exists"; } } else { echo "Error only jpg png and gif under 1mb are accepted"; } } else { echo "Image uploaded"; } mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("accounts") or die(mysql_error()); mysql_query("INSERT INTO `post_photo`(`photos`) VALUES ([value-2])"); ?>