gpt4 book ai didi

php - mysql 查询中奇怪的额外等号。我该如何删除它?

转载 作者:行者123 更新时间:2023-11-29 02:33:08 24 4
gpt4 key购买 nike

我正在尝试弄清楚如何分配 $updateNames 变量以接受 4 个不同的值,从而允许我一次重新上传一个文件。现在,我上传的任何文件都会被放入 name1

这是 php:

    <?php

require_once('storescripts/connect.php');
mysql_select_db($database_phpimage,$phpimage);
error_reporting(E_ALL);
$uploadDir = 'upload/';
if(isset($_POST['upload']))
{


foreach ($_FILES as $file)
{

$fileName = $file['name'];
$tmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileType = $file['type'];

if ($fileName != ""){
$filePath = $uploadDir;
$fileName = str_replace(" ", "_", $fileName);

//Split the name into the base name and extension
$pathInfo = pathinfo($fileName);
$fileName_base = $pathInfo['fileName'];
$fileName_ext = $pathInfo['extension'];

//now we re-assemble the file name, sticking the output of uniqid into it
//and keep doing this in a loop until we generate a name that
//does not already exist (most likely we will get that first try)
do {
$fileName = $fileName_base . uniqid() . '.' . $fileName_ext;
} while (file_exists($filePath.$fileName));

$file_names [] = $fileName;

$result = move_uploaded_file($tmpName, $filePath.$fileName);
}


if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$fileinsert[] = $filePath;
}
}

$mid = mysql_real_escape_string(trim($_POST['mid']));
$cat = mysql_real_escape_string(trim($_POST['cat']));
$item = mysql_real_escape_string(trim($_POST['item']));
$price = mysql_real_escape_string(trim($_POST['price']));
$about = mysql_real_escape_string(trim($_POST['about']));

for($i = 0; $i < 4; $i++)
{
$values[$i] = isset($file_names[$i]) ? mysql_real_escape_string($file_names[$i]) : '';

if($values[$i] != '')
{
$updateVals[] = "name".($i+1)." = '{$values[$i]}'";
}

}
$updateNames = '';
if(count($updateVals))
{
$updateNames = ", " . implode(', ', $updateVals);
}

$update = "INSERT INTO image
(mid, cid, item, price, about, name1, name2, name3, name4)
VALUES
('$mid', '$cat', '$item', '$price', '$about', '$values[0]', '$values[1]', '$values[2]', '$values[3]')
ON DUPLICATE KEY UPDATE
cid = '$cat', item = '$item', price = '$price', about = '$about' $updateNames";
$result = mysql_query($update) or die (mysql_error());

最佳答案

当您填充 $values 数组时,您的 $fields 数组保持为空。因此引用返回空字符串,导致赋值表达式不完整。

关于php - mysql 查询中奇怪的额外等号。我该如何删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9753354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com