Hi I have to build the like of a commercial website for my project and all was going well until I had to try to insert images in a SQL database ; I tried to modify some code that I found online but it is not working.
The idea is to use a form to upload the image but when I click on the submit button on my form the script does nothing it just give me a blank page:
insert.php:
<?php
// Create MySQL login values and
// set them to your login information.
$username = "root";
$password = "I made sure that my pass is correct";
$host = "localhost";
$database = "Binary";
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES["File"]))
{
// Temporary file name stored on the server
$tmpName = $_FILES["File"]["tmp_name"];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO tbl_images ";
$query .= "VALUES ('$data')";
$results = mysql_query($query, $link);
// Print results
print "Thank you, your file has been uploaded.";
}
else
{
print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close($link);
?>
Can someone please help me to get this to work?I badly need that for my project and I am not a php expert at all.