2012-06-25 2 views
-3
내가 mysql을 삽입하기 위해 노력하고있어

에 삽입하지 않습니다하지만 여기, 나에게 내 코드에서 오류가 제공 :PHP는 MySQL의

$result = mysql_query("INSERT INTO property(Pname, P_Price,P_Desc,P_City, P_Size,P_Rooms, P_garage, P_Address, P_Long, P_Lat, P_Sold, Provinces_idProvinces) 
    VALUES('http://10.0.2.2/images/pic3.jpg',98000,'beautifull house','Durban','7m',1,2,'L-377 Umlazi','30.863226','-29.971518',0,'1'"); 

if ($result) { 
     // successfully inserted into database 
     $response["success"] = 1; 
     $response["message"] = $result ; 

     // echoing JSON response 
     echo json_encode($response); 
    } else { 
     // failed to insert row 
     $response["success"] = 0; 
     $response["message"] = "Oops! An error occurred."; 

     echo $response["success"]; 

     // echoing JSON response 
     echo json_encode($response); 
    } 

mysql_close(); 

을 그리고 메시지를 반환 "! 웁 오류가을 발생"어떤 내가 그것을

내 MySQL의 일이 어떻게 얻을 해달라고

CREATE TABLE property (
    idProperty int(11) NOT NULL AUTO_INCREMENT, 
    Pname varchar(45) DEFAULT NULL, 
    P_Price double DEFAULT NULL, 
    P_Desc varchar(45) DEFAULT NULL, 
    P_City varchar(45) DEFAULT NULL, 
    P_Siz varchar(45) DEFAULT NULL, 
    P_Rooms varchar(45) DEFAULT NULL, 
    P_garage int(11) DEFAULT NULL, 
    P_Address varchar(45) DEFAULT NULL, 
    P_Long float (10,6) DEFAULT NULL, 
    P_Lat float (10,6) DEFAULT NULL, 
    P_Sold tinyint(1) DEFAULT '0', 
    Provinces_idProvinces int(11) NOT NULL, 
    PRIMARY KEY (idProperty), 
    KEY fk_Property_Provinces (Provinces_idProvinces), 
    CONSTRAINT fk_Property_Provinces FOREIGN KEY (Provinces_idProvinces) REFERENCES provinces (idProvinces) ON DELETE NO ACTION ON UPDATE NO ACTION 
); 
+1

쿼리를 반향하여 데이터베이스에서 바로 실행하십시오. 그러면 훨씬 더 유용한 오류 메시지가 나타납니다. – andrewsi

+1

andrewsi와 skowron-line이 다음과 같이 말했습니다 :'$ response [ "message"] = "죄송합니다! mysql_error();'- 실제 오류 메시지가 무엇인지 알려주십시오. –

+0

만약 내 데이터베이스에 그것이 삽입되면, 삽입하지만, 이제는 PHP를 사용하여 삽입하고자합니다. – Zamani

답변

3

을 당신이 끝 괄호로 값을 닫지 않았다 생각합니다.

$result = mysql_query(
"INSERT INTO property(Pname, P_Price,P_Desc,P_City, P_Size,P_Rooms, P_garage, P_Address, P_Long, P_Lat, P_Sold, Provinces_idProvinces) 
VALUES('http://10.0.2.2/images/pic3.jpg',98000,'beautifull house','Durban','7m',1,2,'L-377 Umlazi','30.863226','-29.971518',0,'1')"); 
0

당신은 문자열이 아니라 테이블 설명으로 int로는 '1'로 Provinces_idProvinces 있습니다.

이 시도 :

$result = mysql_query("INSERT INTO property(Pname, P_Price,P_Desc,P_City, P_Size,P_Rooms, P_garage, P_Address, P_Long, P_Lat, P_Sold, Provinces_idProvinces) 
    VALUES('http://10.0.2.2/images/pic3.jpg',98000,'beautifull house','Durban','7m',1,2,'L-377 Umlazi','30.863226','-29.971518',0,1)"); 
+0

변경 되었습니까? – Zamani

+1

그는 마지막 값 (Provinces_idProvinces의 경우 1) 주위의 따옴표를 제거했습니다. –

+0

열 Provinces_idProvinces int (11) NOT NULL이 있지만 문자열 인 값 '1'을 삽입하고 있습니다. 따옴표없이 그것을 삽입하는 것은 트릭을해야합니다. – Fluffeh

0

세 가지 문제 :

  1. 당신은
  2. Provinces_idProvinces 후 작은 따옴표를 제거하여 값 문 뒤에 테이블 스키마
  3. 당신은 후행 누락)를 생성하여 MySQL을 대신 P_Size의 P_Siz이

이 문제를 해결했습니다. DEMO (외래 키 연관 제거)