任何人都可以让我知道我在这里做错了什么。虽然UPDATE在php5.5上正常工作但是Insert Into没有将文件名保存到数据库中......所有其他字段都保存没有任何问题。 提前谢谢
if ($_GET['act']=="Add") {
$uploaddir = '/pictures/';
$uploaddir = $uploaddir . basename($_FILES['foto']['name']);
$file=basename($_FILES['foto']['name']);
move_uploaded_file($_FILES['foto']['tmp_name'], $uploaddir);
chmod("$path/pictures/$file",0755);
$title= $_POST['title'];
$intro= $_POST['intro'];
$subtitle= $_POST['subtitle'];
$full= $_POST['full'];
$photodesc= $_POST['photodesc'];
$pq= $_POST['pq'];
$pq2= $_POST['pq2'];
$pq3= $_POST['pq3'];
$pq4= $_POST['pq4'];
$pq5= $_POST['pq5'];
$pq6= $_POST['pq6'];
$pq7= $_POST['pq7'];
$pq8= $_POST['pq8'];
$pq9= $_POST['pq9'];
$pq10= $_POST['pq10'];
$category= $_POST['category'];
$insertquery="INSERT INTO news_publish (`title`, `subtitle`,
`category`, `intro`, `full`, `pq`, `photo`, `sdate` , `ldate`, `frontpage`,
`photodesc`, `pq2`, `pq3`, `pq4`, `pq5`,`pq6`, `pq7`, `pq8`,`pq9`,`pq10`)
values ('$title', '$subtitle', '$category', '$intro', '$full', '$pq',
'$file', '$sdate', '$ldate', '$frontpage',
'$photodesc','$pq2','$pq3','$pq4',
'$pq5','$pq6','$pq7','$pq8','$pq9','$pq10')";
mysqli_query($connect, $insertquery) or die('Error: ' . mysqli_error($connect));
echo "Page Added<br>
Please wait a second, or <a href=\"?go=editremove\">click here</a> ";
echo "<meta http-equiv=\"refresh\" content=\"1;URL=?go=editremove\">";
}
确定页面添加现在正在处理一个图像上传,但是当我尝试上传多个文件时,它会正确地将文件名保存到数据库,但它会将两个图像作为一个图像上传,并将其命名为“image1.jpgimage2.jpg”。
这就是我上传多个文件的方式
$uploaddir = $uploaddir . basename( $_FILES['foto']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto2']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto3']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto4']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto5']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto6']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto7']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto8']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto9']['name']);
$uploaddir = $uploaddir . basename( $_FILES['foto10']['name']);
$uploaddir = $uploaddir . basename( $_FILES['pdf']['name']);
$uploaddir = $uploaddir . basename( $_FILES['katalog']['name']);
$file=basename( $_FILES['foto']['name']);
$file2=basename( $_FILES['foto2']['name']);
$file3=basename( $_FILES['foto3']['name']);
$file4=basename( $_FILES['foto4']['name']);
$file5=basename( $_FILES['foto5']['name']);
$file6=basename( $_FILES['foto6']['name']);
$file7=basename( $_FILES['foto7']['name']);
$file8=basename( $_FILES['foto8']['name']);
$file9=basename( $_FILES['foto9']['name']);
$file10=basename( $_FILES['foto10']['name']);
$file11=basename( $_FILES['pdf']['name']);
$file12=basename( $_FILES['katalog']['name']);
chmod("$uploaddir/$file",0755);
chmod("$uploaddir/$file2",0755);
chmod("$uploaddir/$file3",0755);
chmod("$uploaddir/$file4",0755);
chmod("$uploaddir/$file5",0755);
chmod("$uploaddir/$file6",0755);
chmod("$uploaddir/$file7",0755);
chmod("$uploaddir/$file8",0755);
chmod("$uploaddir/$file9",0755);
chmod("$uploaddir/$file10",0755);
chmod("$uploaddir/$file11",0755);
chmod("$uploaddir/$file12",0755);
move_uploaded_file($_FILES['foto']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto2']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto3']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto4']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto5']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto6']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto7']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto8']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto9']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['foto10']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['pdf']['tmp_name'], $uploaddir);
move_uploaded_file($_FILES['katalog']['tmp_name'], $uploaddir);
答案 0 :(得分:2)
$file11
和$file12
未在您显示的脚本中定义,但用作插入数据库的值。
您想要更新:
$pdf= $_POST['file11'];
$catalog= $_POST['file12'];
因为您插入的变量不是此处声明的变量。
您的整体方法也充满了安全风险和缺陷,Jay Blanchard在评论中给出的链接都应该被阅读并采纳。
好的,为什么没有将值插入数据库的可能点:
执行print_r($file);
并查看MySQL运行之前的值。这表明你的期望吗?
您是否检查过数据库SQL列的类型是否正确,您是不是要尝试将字符串值插入整数列或类似内容。
检查您的列上是否没有阻止您插入非唯一数据的密钥(我知道这对您的MySQL使用级别来说非常非常不可能,但是......)。
< / LI>按Fred-ii-的说法进行操作,并在页面上设置一些错误报告。例如:
error_reporting(E_ALL);
ini_set('display_errors', 1);
检查您的$_FILES['foto']['error']
值是否为零。您的表单是否在HTML中正确设置以接受文件上传?如果您不确定,请Google“如何使用HTML表单上传文件”。
正如Fred-ii-提到的,您需要使用$_POST
或 $_GET
变量,但不能同时使用两者,如果您要发布表单,则不应该在命令行中使用GET变量。澄清您的表单行为。
一旦你确定你需要设置你的enctype="multipart/form-data"
,那么你真的需要了解如何正确使用PHP,以及关闭脚本上的各种安全漏洞然后实现更清洁更整洁的编码,使我们所有人都能更轻松地进行调试。