2017-01-31 61 views
-1

上傳圖像名稱到數據庫時使用查詢插入的正確方法是什麼?這是一個不起作用的短代碼。查詢插入圖像名稱到數據庫

$query = 'INSERT INTO table_name 
    SET images1="' . $_FILES['file1']['name'] . '", 
     images2="' . $_FILES['file2']['name'] . '", 
     images3="' . $_FILES['file3']['name'] . '", 
     images4="' . $_FILES['file4']['name'] . '"' 
+3

查詢是不正確它不是插入查詢 –

+0

我怎樣才能使這個插入到? – user7368271

回答

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'] . '" 
)'; 
4

目前的結構更新SQL,但你正在使用INSERT命令與it.your插入會是這樣的:如果你想更新,然後使用

$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 
+0

如何將此插入命令? – user7368271

+0

@ user7368271使用第一個sql。但在此之前請檢查您是否正確獲取了這些值。 –

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'].'")';