if(isset($_POST['submitted']))
{
//mysql_connect('localhost','root','')or die(mysql_error());
//mysql_select_db('ecommerce');
include_once ('mysql_connect.php');
if(is_uploaded_file($_FILES['image']['tmp_name']))
{
// $image=$_FILES['image']['tmp_name'];
if(move_uploaded_file($_FILES['image']['tmp_name'], "uploads/".$_FILES['image']['name']))
{
if(!empty($_POST['description']))
{
$d=$_POST['description'];
}
else
{
$d=NULL;
}
$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('{$_FILES['image']['name']}',{$_FILES['image']['size']},'{$_FILES['image']['type']}',$d)"
or die(mysql_error());
mysql_query($query);
}
}
}
**There's no error in database connection.The picture also successfully saved inside the folder but no data inserted in mysql. Kindly assist..Your help is much appreciated!
也许这会有所帮助
$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('".$_FILES['image']['name']."',".$_FILES['image']['size'].",'".$_FILES['image']['type']."','".$d."')";
$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('{$_FILES['image']['name']}',{$_FILES['image']['size']},'{$_FILES['image']['type']}','$d')";
mysql_query($query) or die(mysql_error());
I'm assuming your description
field doesn't just take integers. Put single quotes around strings being inserted into the database.
mysql_query is also deprecated. Use mysqli or pdo to perform queries.
$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('{$_FILES['image']['name']}',{$_FILES['image']['size']},'{$_FILES['image']['type']}', '$d')"
mysql_query($query) or die(mysql_error());;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.