这是我上传文件的代码。一切工作都很完美。该代码将文件上传到目标文件夹,并且MySQL查询完美工作,并将所有数据插入数据库中的相关字段。但它不会进入header()函数中提到的页面。它给了我一个错误在这样Mysql文件上传错误?
Error: please try again, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
最后,我认为,当最后一个if($ exe文件)执行
<?php
include('./includes/connection.php');
if(!$_POST['song_name']){
header('location: pro_add.php');
exit;
}
$path = "../upload_data/";
$uniqid = uniqid(strtotime('now'));
$uniq_name = $uniqid .'_'. $_FILES['file']['name'];
$complete_path = $path . $uniq_name;
$move = move_uploaded_file($_FILES['file']['tmp_name'],$complete_path);
if(!$move){
echo 'Error: please try again'."<br/>";
}
$query = mysql_query("INSERT INTO products SET
sub_cat_id='".$_POST['sub_cat_id']."',
song_name='".$_POST['song_name']."',
artist='".$_POST['artist']."',
path='".$complete_path."' ");
$exe = mysql_query($query);
if($exe){
header('location: products.php');
exit;
}else{
echo 'Error: please try again, <br />' . mysql_error();
}
?>
为什么你在mysql_query()的输出上做了一个mysql_query()。这可能是你的问题。另外,在把它们放在数据库附近的任何地方之前,先开始转义你的变量。 –
你也可能想阅读关于http://en.wikipedia.org/wiki/SQL_injection和mysql_real_escape_string() – Bruce