Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP向数据库添加文件路径_Php_Mysql - Fatal编程技术网

PHP向数据库添加文件路径

PHP向数据库添加文件路径,php,mysql,Php,Mysql,我把这个脚本放在一起,将上传文件的文件路径加载到数据库中。但它似乎不起作用。请告诉我任何建议都很好。它基本上是一个简单的表单,允许多个文件上传。我需要将此信息与文件路径一起发送到数据库,以便以后使用。 我得到一个输出警告 这是一个简单的测试,用于检查变量是否已实际发布 这是echo$sql INSERT INTO mediamanagement ( `Project_Name`, `Assigned_To`, `Assign_Date`, `Check_Date`, `Due_Date` )

我把这个脚本放在一起,将上传文件的文件路径加载到数据库中。但它似乎不起作用。请告诉我任何建议都很好。它基本上是一个简单的表单,允许多个文件上传。我需要将此信息与文件路径一起发送到数据库,以便以后使用。 我得到一个输出警告 这是一个简单的测试,用于检查变量是否已实际发布

这是echo$sql

 INSERT INTO mediamanagement ( `Project_Name`, `Assigned_To`, `Assign_Date`, `Check_Date`, `Due_Date` ) VALUES ( "fvfg df fdh bdfgb", "Ramon", "2013-04-01", "2013-04-18", "2013-04-30", Error: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 '' at line 13
        Error: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 '' at line 13
以下是php:

<?php
mysql_connect("MySQLB15.wer.com","york","usa12") or die ('Error:' .mysql_error());
//database connection
    mysql_select_db("mediamanagement");

$project = $_POST['project'];
$assignto = $_POST['assignto'];
$asdate = $_POST['asdate'];

$chdate = $_POST['chdate'];
$ddate = $_POST['ddate'];



$errors = array();
$files = array();
foreach ($_FILES['files'] as $k=>$image) {

    // handle upload errors
    if ($image['error'] != 0 && $image['error'] != 4) {         
        switch ($image['error']) {
            case '1':
            case '2':
                $err = 'The uploaded file exceeds the maximum file size.';
                break;                  
            case '3':
                $err = 'The upload was inturupted, transfer failed.';
                break;
            case '6':
            case '7':
            case '8':
                $err = 'Server error.  Please try again later.';
                break;
        }
        // record error and move on
        $errors[] = array('files'=>$k, 'error'=>$err);
        continue;
    } elseif ($image['error'] == 4) {
        // error 4 means no image was sent
        continue;
    }

    // determine the extension
    $ext = explode('.', $image['name']);
    if (count($ext) != 2) {
        $errors[] = array('files'=>$k, 'error'=>'Could not determine file extension.');
        continue;
    } else {
        switch ($ext[1]) {
            case 'jpg':
            case 'jpeg':
            case 'gif':
            case 'png':
            case 'pdf':
            case 'psd':
            case 'ai':
            case 'pdf':


                break;
            default:
                $errors[] = array('files'=>$k, 'error'=>'Unsupported file extension.');
                continue;
                break;
        }
    }

    // make a random-ish filename
    $filename = time().uniqid(rand(), true) . '.' . $ext[1];
    $path = 'uploads/'.$filename;   // upload directory path is set

    move_uploaded_file($image['tmp_name'], $path);     //  upload the file to the server
    // this is a bad idea right here! Use 775 at least, if possible
    chmod($path,0775);
    $files[] = array('name'=>$filename, 'path'=>$path);
}

// now loop the $files array and put the paths into the database

// you also should do something with the errors listed in $errors
// start building up the SQL query, start with
// some fields that are straightforward


$sql = '
    INSERT INTO mediamanagement (
       `Project_Name`,
        `Assigned_To`,
        `Assign_Date`,
        `Check_Date`,
        `Due_Date`';

// now loop the list of files (5 only), 
// add each needed field

for ($i=1; $i < count($files) && $i < 5; $i++) {
    $sql .= '`files'.$i.'`,';
}

// build out the rest of the query, add values
// for the straightforward fields
$sql .= '

) VALUES (
    "'.$project.'", 
    "'.$assignto.'",
    "'.$asdate.'",
    "'.$chdate.'",
     "'.$ddate.'",
';



// loop the files
$ct = 1;
foreach ($files as $f) {
    $sql .= '"'.$f['name'].'",';
    // only allow 5 files
    if ($ct == 5)
        break;
    $ct++;
}
 ')';




mysql_query($sql) or die ('Error:' .mysql_error());;





?>

<?php
echo("<p><span>Project Name:</span> ".$_POST['project']."</p>");
echo("<p><span>assign to:</span> ".$_POST['assignto']."</p>");
echo("<p><span>Assign Date:</span> ".$_POST['asdate']."</p>");
echo("<p><span>Check Date:</span> ".$_POST['chdate']."</p>");
echo("<p><span>Due Date:</span> ".$_POST['ddate']."</p>");



?>

转储sql查询并发布它
顺便说一句,我不认为你知道你在做什么。。。只需复制并通过其他人拥有的代码

for ($i=1; $i < count($files) && $i < 5; $i++) {
  $sql .= '`files'.$i.'`,';
}
than
) VALUES (

and we got ',) VALUE(    
for($i=1;$i
打印出您的最终SQL语法并检查错误。您发布了这么多代码…但没有发布所需的一件事。
echo$SQL;
的结果转义您的post参数。您的代码容易受到SQL注入的影响。在您做任何其他事情之前,请仔细阅读,因为您在这里给自己制造了一大堆麻烦。您可以不要写这样的代码。你必须把所有的用户数据都添加到一个查询中。使用
mysql\u query
也是一个非常糟糕的主意。阅读sql转义就可以了,不再使用弃用代码。我还是一个书呆子,尽可能多地学习PHP知识。有什么想法可以让这个工作起来并加载我的数据库吗se?我认为你的格式是错误的,因为这没有任何意义。请告诉我什么格式是错误的。我还是初学者,正在学习。任何人都可以帮助解决问题吗?当转储正确时…你忘记关闭“值”和“最后一个”的“)”在VALUES语句中,这是不正确的…这并不能回答问题。若要评论或要求作者澄清,请在他们的帖子下方留下评论。好的,我理解,我必须用这个“)来关闭这些值。“但是,你说的值statamet不正确是什么意思?在你的字段中,你给出了5个字段。。。在VALUES(…)中,第5条语句是“2013-04-30”,在本例中,使用“,”是worong,因为最后一个值没有“,”和“,”,以关闭该值。是否可以发布示例?