我有以下代码问题它不是将数据插入mysql但是将文件上传到目标文件夹可以有人有任何建议吗?虽然它没有显示任何运行时错误。
<?php
include 'db.php';
if (isset($_FILES['photo'])){
$target = 'images/';
if(!is_dir($target)) mkdir($target);
$target = $target . basename( $_FILES['photo']['name']);
$stnam = $_POST['stName'];
$stfat = $_POST['stFname'];
$stdob = $_POST['stDob'];
$stage = $_POST['stAge'];
$stgen = $_POST['stgender'];
$styea = $_POST['stYear'];
$stadd = $_POST['stAddress'];
$fname=($_FILES['photo']['name']);
$tmpName = $_FILES['photo']['tmp_name'];
$fileType = $_FILES['photo']['type'];
$fileSize = $_FILES['photo']['size'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()){
$fname = addslashes($fname);}
$sql = "INSERT INTO socio (stName, stFname, stDob, stAge, stgender, stYear, stAddress, stPhoto, ftype, fsize, content) VALUES ('$stnam','$stfat','$stdob','$stage','$stgen','$styea','$stadd','$fname','$fileType','$fileSize','$content')";
$result = mysqli_query($con, $sql);
if(!$result){
echo"data inserted!";
}else{
echo"data not inserted!";
}
mysqli_close($con);
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>
显示插入的数据!已上传文件TEST.docx,您的信息已添加到目录中,但除了文件外没有数据保存在mysql中。