2013-08-01 35 views
-1

我有這樣的代碼,並由於某種原因,我得到這個錯誤INSERT Error - 如果文件EMPTY功能無法正常工作

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB  server version for the right syntax to use near 's','Used','A Book','1','http://media1.' at  line 2 

CODE:

if(empty($_POST['image'])) { 
$file = 'http://media1.site.org/products/images/no-photo.jpg'; 

} else { 
    define('UPLOAD_DIR', '/products/images/'); 
define('UPLOAD_HOST', 'http://media1.sabinalcanyon.org/products/images/'); 

move_uploaded_file($_FILES['image']['tmp_name'],UPLOAD_DIR.$_FILES['image']['name']); 

$file = UPLOAD_HOST.$_FILES['image']['name']; 
} 

$descedit = "<p>".$_POST['description']."</p>"; 

mysql_query("INSERT INTO products (`title`,`barcode`,`ISBN`,`catagory`,`set_price_start`,`brand`,`condition`,`description`,`amount_stock`,`picurl`) 
VALUES('$_POST[title]','$_POST[barcode]','$_POST[ISBN]','$_POST[catagory]','$_POST[set_price_start]','$_POST[brand]','$_POST[condition]','$descedit','$_POST[amount_stock]','$file')") or die(mysql_error()); 

2號線是這個塊的僅僅是開始的代碼。

+0

很好。你有一個錯誤(和一個大的SQL注入安全漏洞)。我們都去過那裏。現在,*你到底做了什麼來調試這個*? (對於初學者來說,生成的查詢字符串是什麼?) –

+0

檢查你的'$ _POST [品牌]'值。 –

+2

你很容易受到[SQL注入攻擊](http://bobby-tables.com)的影響。你很容易受到文件注入攻擊。 **請勿將此代碼用於生產系統**。 –

回答

1

我只是給你一個例子,你繼續與其他變量。

VALUES('".mysql_real_escape_string($_POST['title'])."',....... 

和你的錯誤

right syntax to use near 's' , 

這是由於$_POST[brand]變量。

我猜你有你的品牌的變量,包括apostrof 's 然後更好地逃避它像

'".mysql_real_escape_string($_POST['brand'])."' 
  • 請翻到PDOMYSQLImysql已經過時的一些值。
+1

如果他們(SQL)想出這樣的錯誤消息,那將是如此的好:**「你在那裏有一個撇號,對它做些什麼。」**(lol) –

+0

:) ,它會很好,然後所有人都會理解它:) –

+0

是的,好像他們不想讓任何人都容易。那麼誰又說編程會很容易(?)好吧,我今天已經學到了一些新東西。 *和平* –