Insert image via text

i am using the ck editor and i wrote this code for insert image in mysql but this code doesn’t insert name file in feild’s path just it insert folder’s name i don’t where’s problem?
i appreciate everyone help me

$uploadDir = 'upload/';
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];

$filePath = $uploadDir . $fileName;
$ext = explode(".", $_FILES['userfile']['name']);
$ext = $ext[ count($ext) - 1 ];

$mime = $_FILES['userfile']['type'];

$valid_ext = array("jpg", "jpeg", "gif", "png", "bmp");
if(in_array($ext, $valid_ext)){
	
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
	
//echo'<font color="#FF0000">Error uploading file</font>';


}}
else{
	
	$select='<font color="#FF0000"><br/>&#1604;&#1591;&#1601;&#1575; &#1740;&#1705; &#1601;&#1575;&#1740;&#1604; &#1575;&#1586; &#1606;&#1608;&#1593; (jpg ,jpeg ,gif ,png ,bmp) &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1705;&#1606;&#1740;&#1583;</font>';
	
	}
	$fileName = addslashes($fileName);
$filePath = addslashes($filePath);

	$ext = explode(".", $_FILES['userfile']['name']);
$ext = $ext[ count($ext) - 1 ];

$mime = $_FILES['userfile']['type'];

$valid_mime = $valid_mime_image;
$valid_ext = array("jpg", "jpeg", "gif", "png", "bmp");


$sw=mysql_query("INSERT INTO message (text1,title,date,visits,path) VALUES('".$editortext."','".$tit."','".jmaketime()."','0','".$filePath."') ");
mysql_query('SET names utf8') or die(mysql_error());

I would echo your variables to see what they contain and you can either comment them out or remove them when the code is working.

This line looks a bit strange:


('".$editortext."','".$tit."','".jmaketime()."','0','".$filePath."') ");

Should it be this:


( $editortext, $tit, jmaketime(), '0', $filePath) ");

I do not know if you can use jmaketime() here; I would have set it into a variable and used the variable instead.

Try this $filePath = $uploadDir.$fileName.$temp_name; instead of this $filePath = $uploadDir.$fileName;