2013-02-11 6 views
0

아래 코드로 일부 데이터를 삽입하고 있지만 삽입하지 않습니다. echo $_REQUEST 데이터로 모든 것을 검사했습니다. 데이터는 모두 출력이 좋지만 데이터는 삽입하지 않습니다.SQL 쿼리를 성공적으로 실행하지 못했습니다.

이 코드를 사용하십시오. 이 내 테이블에 설명되어 나는 그것은이

echo "$bname, $btype, $bemail, $bwebsite, $bphone, $bpostal, $bcountry, $bannertype, 
$bgcolor, $bheadcolor,$bsubheadcolor,$btextcolor"; 

쉽게 에코됩니다

$bname   =$_REQUEST['bname']; 
$btype   =$_REQUEST['btype']; 
$bemail  =$_REQUEST['bemail']; 
$bwebsite  =$_REQUEST['bwebsite']; 
$bphone  =$_REQUEST['bphone']; 
$bpostal  =$_REQUEST['bpostal']; 
$bcountry  =$_REQUEST['bcountry']; 
$bannertype =$_REQUEST['bannertype']; 
$bgcolor  =$_REQUEST['bgcolor']; 
$bheadcolor =$_REQUEST['bheadcolor']; 
$bsubheadcolor =$_REQUEST['bsubheadcolor']; 
$btextcolor =$_REQUEST['btextcolor']; 

형태의 데이터를 잡아하고 있지만 삽입 나던 작업에 올 때 오류

include 'dbconnect.php'; 

$sql="insert into company (business_id, business_name, business_type, bunsiness_email, 

business_website, work_phone, postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('NULL','".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')"; 

mysql_query($sql) or die("An Error Occured while updating"); 
include 'dbclose.php';*/ 

에게 제공

+----------------------------+---------------+------+-----+---------+----------- 
-----+ 
| Field      | Type   | Null | Key | Default | Extra 
| 
+----------------------------+---------------+------+-----+---------+----------- 
-----+ 
| business_id    | int(10)  | NO | PRI | NULL | auto_increment | 
| business_name    | varchar(50) | NO |  | NULL || 
| business_type    | varchar(50) | NO |  | NULL |  | 
| business_email    | varchar(50) | NO |  | NULL | 
| business_website   | varchar(50) | NO |  | NULL | 
| work_phone     | varchar(20) | NO |  | NULL | 
| postal_code    | varchar(20) | NO |  | NULL | 
| business_country   | varchar(20) | NO |  | NULL | 
| banner_type    | varchar(50) | NO |  | NULL | 
| select_bgcolor    | varchar(50) | NO |  | NULL | 
| select_heading1   | varchar(50) | NO |  | NULL | 
| select_heading2   | varchar(50) | NO |  | NULL | 
| select_text    | varchar(50) | NO |  | NULL | 
+1

[** 새로운 코드에서 사용하지 마십시오'mysql_로 *'기능 **] (http://bit.ly/phpmsql). 더 이상 유지 관리되지 않으며 공식적으로 사용되지 않습니다 (https://wiki.php.net/rfc/mysql_deprecation). [** 빨간색 상자 **] (http://j.mp/Te9zIL)를 참조하십시오. 대신 [* prepared statements *] (http://j.mp/T9hLWi)에 대해 알아보고 [PDO] (http://php.net/pdo) 또는 [MySQLi] (http://php.net/)를 사용하십시오. mysqli) - [이 기사] (http://j.mp/QEx8IB)는 어떤 결정을 내리는 데 도움이 될 것입니다. PDO를 선택하면 [여기는 좋은 튜토리얼입니다] (http://j.mp/PoWehJ). –

+0

mysql_error()를 사용하여 오류를 출력하십시오. – Sirko

+2

또한, 당신은 [SQL injections] (http://stackoverflow.com/q/60174) –

답변

1

bunsiness_email가에 business_email을해야한다 (I 열을 business_id하는 인서트를 삭제 한) 그 삽입 열은 bunsiness_email 열이 없기 때문에 완전히 깨뜨릴 것입니다. 준비된 명령문에 대해 배우는 것, 그리고 열리고 닫히는 single 및 double 쿼터 마크를 많이 볼 수있는 시나리오가 있기 때문에 준비된 명령문을 사용하면 훨씬 쉽게 처리 할 수 ​​있고 SQL 주입에 대해보다 안전하게 처리 할 수 ​​있습니다.

+0

Gotcha This thanx @Octopi는 주사에서 보안을 얻는 방법을 더 설명 할 수 있습니다. – Bandayar

+0

Booya, @ John Conde가 첫 번째 댓글에 올린 튜토리얼을 확인하십시오. SQL 주입 문제에 대한 설명과 준비된 명령문으로 해결 방법에 대해 설명합니다. –

0

business_id가 절대로 NULL이 아닙니다. 자동 증가 필드입니다. business_id 이후

$sql="insert into company (business_name, business_type, bunsiness_email, 

business_website, work_phone, postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')"; 
0

는 INSERT 쿼리에 필요하지 않은, 지능 AUTO INCREMENT 컬럼입니다.

$sql = "insert into company (
    business_name, 
    business_type, 
    business_email, 
    business_website, 
    work_phone, 
    postal_code, 
    business_country, 
    banner_type, 
    select_bgcolor, 
    select_heading1, 
    select_heading2, 
    select_text 
    ) values (
     '" . $bname . "', 
     '" . $btype . "', 
     '" . $bemail . "', 
     '" . $bwebsite . "', 
     '" . $bphone . "', 
     '" . $bpostal . "', 
     '" . $bcountry . "', 
     '" . $bannertype . "', 
     '" . $bgcolor . "', 
     '" . $bheadcolor . "', 
     '" . $bsubheadcolor . "', 
      '" . $btextcolor . "' 
    )"; 

그리고 쿼리에서 NULL을 전달하려는 경우 따옴표없이 수행하십시오. 당신은 당신이 business_id 열에 NULL 값을 삽입하려고

$sql="insert into company (business_name, business_type, bunsiness_email, 

business_website, work_phone, postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')"; 

mysql_query($sql) or die("An Error Occured while updating"); 
0

귀하의 business_id는 자동 증가 기본 키입니다. 이 열이 null이 될 수 없기 때문에 (이 기본 키이기 때문에) 당신은

사용하려고하십시오 그렇게 할 수 없습니다

$sql="insert into company (business_name, business_type, bunsiness_email, 

business_website, work_phone, postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')"; 
1

이 오류는 쿼리에서 business_id을 제거주고 쿼리에서 널 (null)로 보낼 수 있도록

0

비즈니스 ID가 기본 키입니다 .it는 자동 증분 값입니다. 따라서 business_id를 삽입하는 동안 NULL로 삽입 할 수 없습니다. 그래서 쿼리는 다음과 같습니다

$sql="insert into company (business_name, business_type, bunsiness_email, 

business_website, work_phone, postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')"; 
관련 문제