我在上传文件时遇到问题。我有以下代码在本地完美工作。现在我已将其上传到服务器,文件上传到我选择的目录但插入语句没有运行。
<?php
require('../conn/include.php');
require('quick.php');
$project=$_POST['project'];
$title=$_POST['title'];
$keyword=$_POST['keyword'];
if(isset($_FILES['image'])) {
$errors=array();
$allowed_ext=array('pdf','doc','docx','ppt','pptx','PDF');
$filename=$_FILES['image']['name'];
$name=stripslashes($filename);
$type=strtolower(end(explode('.',$filename)));
$size=$_FILES['image']['size'];
$file_tmp=$_FILES['image']['tmp_name'];
if(in_array($type,$allowed_ext) ===false) {
$errors[]= "<span class=\"notification n-error\">Extenstion Not Allowed</span>";
}
if($size > 52428800) {
$errors[]= "<span class=\"notification n-error\">File must be less then 25mb</span>";
}if(file_exists('../../Downloads/b/'.$filename)) {
$errors[]= "<span class=\"notification n-error\">File $filname Already Exists in directory</span>";
}if(empty($errors)) {
if(move_uploaded_file($file_tmp, '../../Downloads/b/'.$filename)) {
$insert="Insert into `my`.publication(publ_title,publ_name,project,keyword)VALUE('$title','$name','$project','$keyword')";
//echo $insert;
$que=mysql_query($insert);
echo "<span class=\"notification n-success\">File $filname Uploaded Sucessfully</span>";
}
}else {
foreach($errors as $error) {
echo $error,'<br/>';
}
}
}
?>
答案 0 :(得分:0)
“我已选择但插入语句未运行。”
此行包含VALUE
$insert="Insert into `my`.publication(publ_title,publ_name,project,keyword)
VALUE ('$title','$name','$project','$keyword')";
S--^
应为VALUES
(复数形式)
$insert="Insert into `my`.publication(publ_title,publ_name,project,keyword)
VALUES ('$title','$name','$project','$keyword')";
例如,如果您的数据库连接变量为$con
,请尝试:
$result = mysql_query($insert);
if($result)
{
echo "Successfully updated database";
}
else
{
die('Error: '.mysql_error($con));
}
mysql_close($con);
或尝试
$result = mysql_query($insert,$con);
if($result)
{
echo "Successfully updated database";
}
else
{
die('Error: '.mysql_error($con));
}
mysql_close($con);
并使用示例连接和数据库选择:
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);