将图片名称上传到数据库时使用查询插入的正确方法是什么?这是一个无效的简短代码。
$query = 'INSERT INTO table_name
SET images1="' . $_FILES['file1']['name'] . '",
images2="' . $_FILES['file2']['name'] . '",
images3="' . $_FILES['file3']['name'] . '",
images4="' . $_FILES['file4']['name'] . '"'
答案 0 :(得分:4)
当前的结构是更新sql,但你正在使用insert命令。你的插入将是这样的:
$query='INSERT INTO table_name (images1,images2,images3,images4)
values("'.$_FILES['file1']['name'].'", "'.$_FILES['file2']['name'].'",
"'.$_FILES['file3']['name'].'", "'.$_FILES['file4']['name'].'")';
如果您想要更新,请使用:
$query='update table_name SET images1="'.$_FILES['file1']['name'].'",
images2="'.$_FILES['file2']['name'].'", images3="'.$_FILES['file3']['name'].'",
images4="'.$_FILES['file4']['name'].'"' // add where clause if any
答案 1 :(得分:3)
这应该是UPDATE查询:
$query = 'INSERT INTO table_name
SET images1="' . $_FILES['file1']['name'] . '",
images2="' . $_FILES['file2']['name'] . '",
images3="' . $_FILES['file3']['name'] . '",
images4="' . $_FILES['file4']['name'] . '"';
INSERT应该是:
$query = 'INSERT INTO table_name (images1, images2, images3, images4)
values( "' . $_FILES['file1']['name'] . '",
"' . $_FILES['file2']['name'] . '",
"' . $_FILES['file3']['name'] . '",
"' . $_FILES['file4']['name'] . '"
)';
答案 2 :(得分:0)
插入查询就像
INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
您正在使用column_name=vlaue
编写更新查询
所以你的查询将是
$query='INSERT INTO table_name (images1,images2,images3,images4)
values("'.$_FILES['file1']['name'].'", "'.$_FILES['file2']['name'].'", "'.$_FILES['file3']['name'].'", "'.$_FILES['file4']['name'].'")';