2012-05-25 86 views
-4

我試圖將數據插入到數據庫中的兩個表,兩個查詢的一個工作,即使它們是相同的,只有列被更改名稱和數據庫名稱。插入到表中沒有工作

下面是插入代碼,...

$requesttitle = $_POST["requesttitle"]; 
       $requesturl = $_POST["requesturl"]; 
       $requestcap = $_POST["requestcap"]; 
       $requestdestype = $_POST["requestdestype"]; 
       $requestdbtype = $_POST['requestdbtype']; 
       $accountid=$_SESSION['username']; 
       $deptname = $_POST['deptname']; 
       $contactname = $_POST['contactname']; 
       $contactnum = $_POST['contactnum']; 
       $contactemail = $_POST['contactemail']; 
       $startdate = $_POST['startdate']; 
       $enddate = $_POST['enddate']; 

       if(trim($requesttitle)=="") return "<p>Error in submitting request. Request Title is empty!</p>"; 
       if(trim($requesturl)=="") return "<p>Error in submitting request. Request URL is empty!</p>"; 
       if(trim($requestcap)=="") return "<p>Error in submitting request. Storage Capacity is empty!</p>"; 
       if(trim($requestdestype)=="") return "<p>Error in submitting request. Design Type is empty!</p>"; 
       if(trim($requestdbtype)=="") return "<p>Error in submitting request. Database Type is empty!</p>"; 
       if(trim($deptname)=="") return "<p>Error in submitting request. Requesting Department is empty!</p>"; 
       if(trim($contactname)=="") return "<p>Error in submitting request. Contact Person is empty!</p>"; 
       if(trim($contactnum)=="") return "<p>Error in submitting request. Contact Number is empty!</p>"; 
       if(trim($contactemail)=="") return "<p>Error in submitting request. Contact E-mail is empty!</p>"; 
       if(trim($startdate)=="") return "<p>Error in submitting request. Contact E-mail is empty!</p>"; 
       if(trim($enddate)=="") return "<p>Error in submitting request. Contact E-mail is empty!</p>"; 

       //$sql = "insert into webhostrequest (requesttitle, requesturl, requestcap, requestdestype, requestdbtype, accountid, deptname, contactname, contactnum, contactemail, startdate, enddate, recentact) values ('$requesttitle', '$requesturl', '$requestcap', '$requestdestype', '$requestdbtype', '$accountid', '$deptname', '$contactname', '$contactnum', '$contactemail', '$startdate', '$enddate', now())"; 
       //$result = mysql_query($sql) or die ("Error in submitting request. $sql".mysql_error()); 

       $sql2 = "insert into req_servicerequest (title, url, memory, design, database, accountid, deptname, contactname, contactnum, contactemail, startdate, enddate, recentact) values ('$requesttitle', '$requesturl', '$requestcap', '$requestdestype', '$requestdbtype', '$accountid', '$deptname', '$contactname', '$contactnum', '$contactemail', '$startdate', '$enddate', now())"; 
       $result2 = mysql_query($sql2) or die ("Error in submitting request. $sql2".mysql_error()); 

而這裏的誤差,...

提交請求時出錯。插入到req_servicerequest(標題, url,內存,設計,數據庫,accountid,deptname,聯繫人名稱, contactnum,contactemail,startdate,enddate,recentact)值('A', 'http://www.kimbra.org/ ' '500', 'HTML/XHML/XML', 'DB2', '測試', 'UST - 步驟', '詹姆斯', '09151273507', '[email protected]',' 2012-04- 10','2012-05-24','now()')你的SQL語法有錯誤;檢查對應於你的MySQL服務器版本的權利 語法使用附近的 手冊「數據庫,ACCOUNTID,DEPTNAME名稱,聯繫人姓名, contactnum,contactemail,開始日期,」在1號線

+5

數據庫是一個保留字。 http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html – 2012-05-25 04:01:16

+0

該代碼需要一些優化和sql注入消毒。 – tim

回答

4

數據庫是一個關鍵字MySQL的。像這樣逃脫它:`數據庫`,或者更好的,重命名你的列。