插入表中不起作用

时间:2012-05-25 03:57:44

标签: php mysql insert

我正在尝试将数据插入数据库中的两个表中,两个查询中的一个即使它们相同也可以工作,只更改了列名和数据库名。

这是插入的代码,......

$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(标题,   网址,内存,设计,数据库,accountid,deptname,contactname,   contactnum,contactemail,startdate,enddate,recentact)值('A',   'http://www.kimbra.org/','500','HTML / XHML / XML','DB2','test','UST    - Steps','james','09151273507','test@reply.mail','2012-04-10','2012-05-24','now()')您的SQL语法有错误;检查   手册,对应右边的MySQL服务器版本   在'database,accountid,deptname,contactname附近使用的语法,   contactnum,contactemail,startdate,'第1行

1 个答案:

答案 0 :(得分:4)

database是MySQL中的关键字。像这样逃避它:`database`,或者更好,重命名你的列。