Upload image ,insert name and path in databse based on value

I have the following code wich works after submitting my form: I'm getting the photo wich is upload, in my upload folder.

Now i want to Insert this photo name and path in my database.. Example: If image name is 6.jpg, I want in my databse name=6.jpg and path=uploads/6.jpg

html:

<form method="post" enctype="multipart/form-data">
 <input type="file" name="foto">
  <input type="submit" name="submit">

php:

<?php
 if (isset($_POST['submit']) && empty($errors) === true )
 {
$name=basename($_FILES['foto']['name']);
$t_name=$_FILES['foto']['tmp_name'];
$dir='upload';
if(move_uploaded_file($t_name,$dir."/".$name))
{


}
else
{

}
 }
?>

Answers


<?php
if(move_uploaded_file($t_name,$dir."/".$name))
{
     mysql_connect('localhost','username','password');
     mysql_select_db('yourdb');
     $path=$dir."/".$name;
     $sql="INSERT INTO `your_table`(`name`,`path`) values ('".$name."','".$path."')";
     $result=mysql_query($sql);
     if($result){
         echo"Successfully added to db";
     }

}
else
{
     echo "Sorry.File Upload failed";
}

?>

Need Your Help

Unable to connect to remote SQL Server Express Edition

c# visual-studio-2012 sql-server-express

So, I'm having trouble connecting to my remote SQL Express server running on my Server 2008R2 application test server with IIS7, .NET Framework 4.5 and WebDeploy. I have setup my sql server with the

Window functions assume null sorts low - expected behavior?

sql sql-server sql-server-2012

The following will not properly count nulls within a window...